本文章由孙旭编写,未经允许,不要传播啦
stack segment
db 1024 dup(?)
stack ends
data segment
x dw ?
y dw ?
zl dw ?
zh dw ?
tag db 1
data ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
sub sp,4
call read
mov x,ax
push ax
call read
mov y,ax
push ax
call Calulate;求结果
call Print
mov ah,4ch
int 21h
;运算子程序
Calulate proc
push bp
mov bp,sp
mov ax,[bp+6]
mov bx,[bp+4]
imul bx
mov bx,ax
mov cx,dx
mov ax,[bp+6]
cwd
add bx,ax
adc cx,dx
mov ax,[bp+4]
cwd
sub bx,ax
sbb cx,dx
mov word ptr [bp+8],bx
mov word ptr [bp+10],cx
mov ax,[bp+8]
mov zl,ax
mov ax,[bp+10]
mov zh,ax
pop bp
ret 4
Calulate endp
;转换为十进制输出
Print proc
xor si,si
xor ax,ax
cwd
cmp cx,0
jae next1
and cx,7fffh
mov tag,0
next1: cmp cx,0
ja next2
cmp bx,10
jae next2
inc si
push bx
mov bx,ax
mov cx,dx
xor ax,ax
cwd
cmp cx,0
jg next3
cmp bx,10
jae next3
inc si
push bx
jmp done1
next2: add ax,1
adc dx,0
sub bx,10
sbb cx,0
next3: jmp next1
done1: mov al,tag
cmp al, 1
je next4
mov dl,'-'
mov ah,02h
int 21h
next4: mov cx,si
again: pop dx
or dl,30h
mov ah,02h
int 21h
loop again
Print endp
;输入十进制数
read proc
push bx
push cx
push dx
xor bx,bx
xor cx,cx
mov ah,1
int 21h
cmp al,'+'
jz read1
cmp al,'-'
jnz read2
mov cx,-1
read1: mov ah,1
int 21h
read2: cmp al,'0'
jb read3
cmp al,'9'
ja read3
sub al,30h
shl bx,1
mov dx,bx
shl bx,1
shl bx,1
add bx,dx
mov ah,0
add bx,ax
jmp read1
read3: cmp cx,0
jz read4
neg bx
read4: mov ax,bx
pop dx
pop cx
pop bx
ret
read endp
code ends
end start