;assume cs:code,ds:data,ss:stack
data segment
divisors DW 10000, 1000, 100, 10, 1
results DB 0,0,0,0,0,"$" ;存放五位数ASCII码
data ends
stack segment
; dw 8 dup(0)
stack ends
code segment
assume cs:code
main proc far
mov ax, data
mov ds, ax
now:
mov ax, 0
call input
push bx
;----------
cmp al, '+'
jz plus
cmp al, '-'
jz minus
cmp al, '*'
jz mult
cmp al, '/'
jz divd
;------------------------
plus:
call input
pop ax
add ax, bx
jmp next
minus:
call input
pop ax
cmp ax, bx
jl less
sub ax, bx
jmp next
less:
sub ax, bx
neg ax
push ax
mov dl, '-'
mov ah, 02h
int 21h
pop ax
jmp next
mult:
call input
pop ax
mul bx
jmp next
divd:
call input
pop ax
cmp ax, bx
jl less2
jmp next
less2:
push ax
mov dl, 30h
mov ah, 02h
int 21h
mov dl, '.'
mov ah, 02h
pop ax
jmp next
;---------
MOV DL,'~'
next:
call output
jmp now
mov ah, 4ch
int 21h
ret
main endp
;---------------------
input proc near
mov bx, 0
num:
mov ah, 1
int 21h
cmp al, 'D'
jz clear
cmp al, '+'
jz exit
cmp al, '-'
jz exit
cmp al, '*'
jz exit
cmp al, '/'
jz exit
sub al, 30h
jl exit
cmp al, 9
jG exit
cbw
xchg ax, bx
mov cx, 0
mul cx
xchg ax, bx
add bx, ax
jmp num
clear:
mov dl, 0dh
mov ah, 2
int 21h
mov dl, 0ah
mov ah, 2
int 21h
mov ax, 0
mov bx, 0
jmp num
exit:
ret
input endp
;----------------------
output proc near
mov si, offset divisors
mov di, offset results
mov cx, 5
cal:
mov dx, 0
div word ptr [si]
add al, 30h
mov byte ptr [di], al
inc di
add si, 2
mov ax, dx
loop cal
mov cx, 4
mov di, offset results
nz:
cmp byte ptr [di], '0'
jne print
inc di
loop nz
print:
mov dx, di
mov ah, 9
int 21h
ret
output endp
;------------
code ends
end main
汇编语言课设-计算器
最新推荐文章于 2025-07-03 15:02:17 发布