下面是我编写四则运算程序,除法一直提示溢出(2除2都溢出),想编出带余数的,求高人指点啊!!(由于刚刚开始学,问题可能比较幼稚,请不要见笑!)
str00 macro st
lea dx,st
mov ah,09h
int 21h
endm
;============================
data segment
x dw ?
y dw ?
symbol db ?
z dw ?
cont db ?
jiemian db '=================================',13,10
db '= size system =',13,10
db '=1.add 2.sub 3.mul 4.div 5.exit =',13,10
db '=================================','$'
str0 db 13,10,'x=$'
str1 db 13,10,'y=$'
str2 db 13,10,'input(+-*/):$'
str3 db 'Not a yunsuanfu'
str4 db 13,10,'z=$'
str5 db 13,10,'continue(y/n):$'
str6 db 13,10,'overfolw$'
str7 db 13,10,'yushu:$'
data ends
;===========================
code segment
assume cs:code,ds:data
main proc
start:
mov ax,data
mov ds,ax
str00 jiemian
begin: str00 str0
call decibin
mov x,bx
str00 str1
call decibin
mov y,bx
call yunsuan
exit:
mov ah,4ch
int 21h
main endp
;==============================
yunsuan proc
str00 str2
push ax
mov ah,01h
int 21h
mov dx,0
mov dl,al
pop ax
mov symbol,dl
;str00 str5
cmp symbol,'+'
je jia
cmp symbol,'-'
je jian0
cmp symbol,'*'
je cheng
cmp symbol,'/'
je chu
str00 str3
ret
jia:
mov ax,x
add ax,y
mov z,ax
jmp jieguo
jian0:
mov ax,x
mov bx,y
cmp ax,bx
jl jian1
jian1:
xchg ax,bx
sub ax,bx
mov z,ax
jmp jieguo0
jian2:
mov ax,x
sub ax,y
mov z,ax
jmp jieguo
cheng:
mov ax,x
mul y
cmp dx,0
jg error
mov z,ax
jmp jieguo
chu:
push ax
push bx
push dx
mov ax,x
div y
cmp dx,0
jnz jieguo1
mov z,ax
pop ax
pop bx
pop dx
jmp jieguo
jieguo:
str00 str4
mov bx,z
call binidec
jmp continue
jieguo0:
str00 str4
mov ah,02h
mov dl,'-'
int 21h
mov bx,z
call binidec
jmp continue
jieguo1:
str00 str4
mov bx,z
call binidec
str00 str7
mov dh,0
mov ah,02h
int 21h
jmp continue
continue:
str00 str5
push ax
mov ah,01h
int 21h
mov dx,0
mov dl,al
pop ax
mov cont,dl
cmp cont,'y'
jz begin
cmp cont,'n'
jz exit
error:
str00 str6
jmp continue
yunsuan endp
;==============================
decibin proc
mov bx,0
rulop:
mov ah,01h
int 21h
cmp al,30h
jl ruexit
cmp al,39h
jg ruexit
sub al,30h
cbw
xchg ax,bx
mov cx,10
mul cx
add bx,ax
jmp rulop
ruexit:
ret
decibin endp
;==============================
binidec proc
cmp bx,0
jnz clop0
mov al,02h
mov dl,'0'
add dl,30h
int 21h
jmp chuexit
clop0: mov cx,5
clop1: mov ax,bx
mov dx,0
mov si,10
div si
push dx
mov bx,ax
loop clop1
mov bp,0
mov cx,5
clop2: pop dx
cmp dl,0
jnz clop3
cmp bp,0
jz clop4
clop3:
mov bp,1
mov ah,02h
add dl,30h
int 21h
clop4:
loop clop2
chuexit:
ret
binidec endp
;========================================