📄 jisuanqi.asm
字号:
data segment ;数据段
strR db 0ah,0dh,'result=','$'
strA db 0ah,0dh,' number:20071120105 name:Wanglijuan',0ah,0dh
db '---------------------------------------------',0ah,0dh
db 'Please input two number(-9999~9999):',0ah,0dh ;提示输入两个数A、B
db 'The first number: A=','$'
strB db 0ah,0dh,'The second number: B=','$'
strE db 0ah,0dh,'Please check your input and enter again!',0ah,0dh,'$' ;提示错误
strC db 0ah,0dh,'---------------------------------------' ;选择运算界面
db 0ah,0dh,'Please input your choice to operate:'
db 0ah,0dh,'1.A+B'
db 0ah,0dh,'2.A-B'
db 0ah,0dh,'3.A*B'
db 0ah,0dh,'4.A/B',0ah,0dh,'$'
strD db 0ah,0dh,'---------------------------------------' ;选择显示方式界面
db 0ah,0dh,'Please input your choice to display:',0ah,0dh
db '1.binary(2)',0ah,0dh
db '2.oct(8)',0ah,0dh
db '3.dec(10)',0ah,0dh
db '4.hex(16)',0ah,0dh,'$'
strH db 0ah,0dh,'$' ;回车换行
strdot db '…','$' ;后跟余数
stA db 5 ;第一个数A(无符号)
db ?
db 5 dup(0)
stB db 5 ;第二个数B(无符号)
db ?
db 5 dup(0)
stAt db 6 ;A(有符号)
db ?
signA db 6 dup(0)
stBt db 6 ;B(有符号)
db ?
signB db 6 dup(0)
sA db 0
db 0
sB db 0
db 0
sC db 0
sD db 0
sFH db 0
sdec db 0
data ends
check macro num,num2 ;检测输入是否合法宏
local error,start,endl,sig,sta1
lea dx,num2
inc dx
mov cx,0
lea bx,num
add bx,2
mov cl,num+1
cmp cl,0
jz error
mov al,[bx]
cmp al,'+'
jz sig
cmp al,'-'
jz sig
cmp al,'0'
jz sig
cmp cl,5
jz error
sta1: push bx
mov bx,dx
mov [bx],cl
pop bx
inc dx
start: mov al,[bx]
cmp al,30h
jb error
cmp al,39h
jg error
inc bx
push bx
mov bx,dx
mov [bx],al
pop bx
inc dx
loop start
mov ax,1
jmp endl
error: mov ax,0
jmp endl
sig: inc bx
dec cl
jmp sta1
endl:
endm
conver macro stt,wt
local start
mov cx,0
mov di,1
mov bx,offset stt
inc bx
mov cl,[bx]
add bx,cx
start: xor ax,ax
mov al,[bx]
sub al,30h
mul di
mov dl,wt
mov dh,[wt+1]
add ax,dx
mov wt,al
mov [wt+1],ah
mov ax,di
mov di,10
mul di
mov di,ax
dec bx
loop start
xor ax,ax
mov bx,0
mov cx,0
mov dx,0
endm
playbin macro play
local start,bin0
mov cx,16
xor ax,ax
mov ah,2
mov dx,0
start: mov dl,30h
rol play,1
jnc bin0
inc dl
bin0:
int 21h
loop start
endm
playoctt macro octt
local start
start: mov ah,2
push cx
mov cx,3
rol octt,cl
mov dx,octt
and dx,7
add dl,30h
int 21h
pop cx
loop start
endm
playoct macro play1,play2
local t2,oct0,endl
mov ah,2
cmp play1,0
jnz t2
mov dl,30h
rol play2,1
jnc oct0
inc dl
oct0: int 21h
mov cx,5
playoctt play2
jmp endl
t2: mov cx,2
rol play1,cl
mov cx,4
playoctt play1
mov cx,2
rol play1,cl
rol play2,1
rcl play1,1
mov dx,play1
and dx,7
add dx,30h
int 21h
mov cx,5
playoctt play2
endl:
endm
playdec32 macro play1,play2
local dec32ne,dec32end2,start
mov ax,55dh
mov bx,4a80h
mov cx,98h
mov dx,9680h
push cx
push dx
mov cx,9
playdec32f play1,play2
mov ax,89h
mov bx,5440h
mov cx,0fh
mov dx,4240h
push cx
push dx
mov cx,9
playdec32f play1,play2
mov ax,0dh
mov bx,0bba0h
mov cx,1h
mov dx,86a0h
push cx
push dx
mov cx,9
playdec32f play1,play2
mov ax,1h
mov bx,5f90h
mov cx,0h
mov dx,2710h
push cx
push dx
mov cx,9
playdec32f play1,play2
mov bx,1000
mov ax,9
displays play2
mov bx,100
mov ax,9
displays play2
mov bx,10
mov ax,9
displays play2
mov bx,1
mov ax,9
displays play2
endm
playdec32f macro play1,play2
local dec32ne,dec32end2,start,decend,dec32nn
start: cmp ax,play1
jg dec32ne
jb dec32nn
cmp bx,play2
ja dec32ne
dec32nn: push ax
push bx
mov ah,2
mov dl,30h
add dl,cl
int 21h
pop bx
pop ax
sub play2,bx
sbb play1,ax
jmp dec32end2
dec32ne: mov sdec,cl
pop dx
pop cx
sub bx,dx
sbb ax,cx
push cx
push dx
mov cl,sdec
loop start
dec32end2: pop dx
pop dx
cmp cl,0
jnz decend
mov dl,30h
mov ah,2
int 21h
decend:
endm
playdec16 macro play
mov bx,10000
mov ax,6
displays play
mov bx,1000
mov ax,9
displays play
mov bx,100
mov ax,9
displays play
mov bx,10
mov ax,9
displays play
mov bx,1
mov ax,9
displays play
endm
displays macro play
local next,endl,start,endll
mov cx,ax
start: cmp cl,1
jb endl
mul bx
cmp play,ax
jnb next
dec cl
mov ax,cx
jmp start
endl: mov dl,30h
mov ah,2
int 21h
jmp endll
next: sub play,ax
mov dl,cl
add dl,30h
mov ah,2
int 21h
endll:
endm
playhex macro play
local start,next
mov cx,4
mov ah,2
start: push cx
mov cl,4
rol play,cl
mov dx,play
and dx,0fh
cmp dl,0ah
jb next
add dl,7
next: add dl,30h
int 21h
pop cx
loop start
endm
playdot macro ;输出...宏
mov ah,9
mov dx,offset strdot
int 21h
endm
writeF macro ;负数标记
mov al,1
mov sFH,al
endm
adjcmp macro ;adjust中的一个比较宏
mov al,sA
mov ah,[sA+1]
mov dl,sB
mov dh,[sB+1]
cmp ax,dx
endm
adjcc macro ;adjust中的一个比较宏
local adjnext,adjne11
mov al,sC
cmp al,'1'
jz adjnext
cmp al,'2'
jz adjnext
cmp bl,0
jz adjne11
cmp bl,3
jz adjne11
writeF
adjne11:
ret
adjnext:
endm
code segment ;代码段
assume cs:code,ds:data
main: mov ax,data
mov ds,ax
xor ax,ax
call inputm ;输入子程序
call choices ;选择子程序
conver stA,sA ;对数据A进行转换
conver stB,sB ;对数据B进行转换
call adjust ;显示及计算前期处理
call calc ;计算子程序
call display ;显示子程序
mov ah,01h
int 21h
mov ah,4ch
int 21h
inputm proc
stinA: mov ah,9
mov dx,offset strA
int 21h
mov ah,10
mov dx,offset stAt
int 21h
check stAt,stA
cmp al,0
jz errinA ;A的输入及检查
stinB: mov ah,9
mov dx,offset strB
int 21h
mov ah,10
mov dx,offset stBt
int 21h
mov ah,9
mov dx,offset strH
int 21h
check stBt,stB
cmp al,0
jz errinB ;B的输入及检查
jmp right
errinA: mov ah,9 ;错误处理
mov dx,offset strE
int 21h
jmp stinA
errinB: mov ah,9
mov dx,offset strE
int 21h
jmp stinB
right: mov bx,0
mov cx,0
mov dx,0
xor ax,ax
ret
inputm endp
choices proc
chstA: mov ah,9
mov dx,offset strC
int 21h
mov ah,1
int 21h
mov sC,al
cmp al,'1'
jc cheor
cmp al,'5'
ja cheor
jmp chnext
cheor: mov ah,9
mov dx,offset strE
int 21h
xor ax,ax
jmp chstA
chnext: mov ah,9
mov dx,offset strD
int 21h
mov ah,1
int 21h
mov sD,al
cmp al,'1'
jc cheorB
cmp al,'5'
ja cheorB
jmp chend
cheorB: mov ah,9
mov dx,offset strE
int 21h
xor ax,ax
jmp chnext
chend: xor ax,ax
mov dx,ax
ret
choices endp
adjust proc
lea dx,strR
mov ah,9
int 21h
mov bl,signA
mov bh,signB
cmp bl,'-'
jz adjAF
cmp bh,'-'
jz adjAZBF
mov bl,0
jmp adjstr
adjAZBF: mov bl,1
jmp adjstr1
adjAF: cmp bh,'-'
jz adjFFF
mov bl,2
jmp adjstr2
adjFFF: mov bl,3
jmp adjstr3
adjstr: adjcc
cmp al,'1'
jz adjad
mov al,sA
mov ah,[sA+1]
mov dl,sB
mov dh,[sB+1]
cmp ax,dx
jnb adjad
writeF
adjad: ret
adjstr1: adjcc
cmp al,'1'
jnz str1sub
mov al,'2'
mov sC,al
adjcmp
jnb st1next
writeF
st1next: ret
str1sub:
mov al,'1'
mov sC,al
ret
adjstr2: adjcc
cmp al,'2'
jz str2sub
mov al,'2'
mov sC,al
adjcmp
jng str2next
writeF
str2next: ret
str2sub:
writeF
mov al,'1'
mov sC,al
ret
adjstr3: adjcc
cmp al,'2'
jz str3sub
writeF
ret
str3sub: adjcmp
jng str3next
writeF
str3next: ret
adjust endp
calc proc
calcm: xor ax,ax
mov dx,ax
mov al,[sB]
mov ah,[sB+1]
mov di,ax
mov al,[sA]
mov ah,[sA+1]
mov bl,[sC]
cmp bl,'2'
jz subm
cmp bl,'3'
jz mulm
cmp bl,'4'
jz divm
add ax,di
mov dx,0
jmp calend
subm: cmp ax,di
jg submne
xchg ax,di
submne: sub ax,di
mov dx,0
jmp calend
mulm: mul di
jmp calend
divm: div di
jmp calend
calend: mov si,ax
mov di,dx
mov al,[sFH]
cmp al,1
jnz calendl
call calcf
calendl: xor ax,ax
mov dx,ax
mov bx,ax
mov cx,ax
ret
calc endp
calcf proc
mov al,sD
cmp al,'3'
jnz calcfne
mov dl,'-'
mov ah,2
int 21h
ret
calcfne: mov al,sC
cmp al,'3'
jz calfcf
not si
add si,1
not di
add di,1
ret
calfcf: not si
not di
add si,1
adc di,0
ret
calcf endp
display proc
mov dx,0
mov bl,[sD]
mov bh,[sC]
cmp bl,'2'
jz octd1
cmp bl,'3'
jz decd1
cmp bl,'4'
jz hexd1
cmp bh,'3'
jz bincx
cmp bh,'4'
jz bincy
playbin si
ret
octd1: jmp octd
decd1: jmp decd2
hexd1: jmp hexd2
bincx: playbin di
playbin si
ret
bincy: playbin si
playdot
playbin di
ret
decd2: jmp decd
octd: cmp bh,'4'
jz octcy1
playoct di,si
ret
octcy1: jmp octcy
hexd2: jmp hexd
octcy: playoct dx,si
playdot
mov dx,0
playoct dx,di
ret
decd: call decff
ret
hexd: cmp bh,'3'
jz hexcx
cmp bh,'4'
jz hexcy
playhex si
ret
hexcx: playhex di
playhex si
ret
hexcy: playhex si
playdot
playhex di
endmml: ret
display endp
decff proc
cmp bh,'4'
jz decffd1
cmp bh,'3'
jz decffc1
jmp nnnnnf
decffd1: jmp decffd
decffc1: jmp decffc
nnnnnf: playdec16 si
ret
decffd: playdec16 si
playdot
mov al,sFH
cmp al,1
jnz decfft
mov ah,2
mov dl,'-'
int 21h
decfft: playdec16 di
ret
decffc: playdec32 di,si
ret
decff endp
code ends
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -