📄 size.asm
字号:
data segment
str0 db 13,10,'+++++++++++++++++++++++++++'
db 13,10,'| Welcome you |'
db 13,10,'| 1.add 2.sub |'
db 13,10,'| 3.mul 4.div |'
db 13,10,'| 5.exit |'
db 13,10,'+++++++++++++++++++++++++++','$'
str1 db 13,10,'x1=','$'
str2 db 13,10,'x2=','$'
str3 db 13,10,'x1+x2=','$'
str4 db 13,10,'x1-x2=','$'
str5 db 13,10,'x1*x2=','$'
str6 db 13,10,'x1/x2=','$'
str7 db 13,10,'Please select (1-5): ','$'
x1 dw ?
x2 dw ?
data ends
;===================================
code segment
assume cs:code,ds:data,es:data
main proc
start:
mov ax,data
mov ds,ax
call select
exit:
mov ah,4ch
int 21h
main endp
;-------------------------------
select proc
mov ah,09h ;menu display 显示菜单
lea dx,str0
int 21h
loop0:
mov ah,09h ;output choice
lea dx,str7
int 21h
mov ah,01h ;judge choice and go
int 21h
cmp al,31h
jz loop1
cmp al,32h
jz loop2
cmp al,33h
jz loop3
cmp al,34h
jz loop4
cmp al,35h
jmp exit
loop1:
call add_n
jmp loop0
loop2:
call sub_n
jmp loop0
loop3:
call mul_n
jmp loop0
loop4:
call div_n
jmp loop0
ret
select endp
;-------------------------------
add_n proc ;加法子块
call input ;input x1 and x2
mov ah,09h ;display 'x1+x2='
lea dx,str3
int 21h
mov ax,x1
add ax,x2
mov bx,ax
call binidec ;output the result of add
ret
add_n endp
;------------------------------
sub_n proc ;减法子块
call input ;input x1 and x2
mov ah,09h ;display 'x1-x2='
lea dx,str4
int 21h
mov si,x1
mov di,x2
cmp si,di
jg loop7
mov ah,02h
mov dl,'-'
int 21h
sub di,si
mov bx,di
call binidec
jmp loop8
loop7:
sub si,di
mov bx,si
call binidec ;output the result of sub
loop8:
ret
sub_n endp
;------------------------------
mul_n proc ;乘法子块
call input ;input x1 and x2
mov ah,09h ;display 'x1*x2='
lea dx,str5
int 21h
mov ax,x1
mul x2 ;remember mul only have src
mov bx,ax
call binidec ;output the result of mul
ret
mul_n endp
;------------------------------
div_n proc ;除法子块
call input ;input x1 and x2
mov ah,09h ;display 'x1/x2='
lea dx,str6
int 21h
mov ax,x1
cwd
div x2 ;remember that div only have scr jian shu
mov bx,ax
call binidec ;output the result of div
ret
div_n endp
;-------------------------------
input proc ;输入子块
mov ah,09h ;tishi x1
lea dx,str1
int 21h
call decibin ;input x1
mov x1,bx
mov ah,09h ;tishi x2
lea dx,str2
int 21h
call decibin ;input x2
mov x2,bx
ret
input endp
;---------------------------------
decibin proc ;字符转换
mov bx,0
dblop1:
mov ah,01h
int 21h
sub al,30h
cmp al,0
jl dbexit
cmp al,9
jg dbexit
cbw
xchg ax,bx
mov si,10
mul si
xchg ax,bx
add bx,ax
jmp dblop1
dbexit:
ret
decibin endp
;--------------------------------
binidec proc uses cx ;显示子程序
mov si,0
mov cx,10000
call dec_div
mov cx,1000
call dec_div
mov cx,100
call dec_div
mov cx,10
call dec_div
mov cx,1
call dec_div
bdexit: ret
binidec endp
;------------------------------------------------------------------------------------------------------------
dec_div proc uses ax cx dx ;显示一个字符
mov ax,bx
mov dx,0
div cx
mov bx,dx
cmp al,0
jnz ddlop1
cmp si,0
jnz ddlop1
jmp ddexit
ddlop1:
mov si,1
mov dl,al
add dl,30h
mov ah,02h
int 21h
ddexit:
ret
dec_div endp
;--------------------------------
code ends
;================================
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -