📄 shift.asm
字号:
data segment
strdec db 'the result in ten is:',0dh,0ah,'$'
strhex db 'the result in sixteen is:',0dh,0ah,'$'
streight db 'the result in eight is:',0dh,0ah,'$'
input1 db 'Please input the first operator(0--65535):$'
input2 db 'Please input the second operator(0--65535):$'
input3 db 'Please input the operate type(choose +,-,*,/):$'
continue db 'If you want to calculate another?(choose y/n):$'
data ends
sseg segment stack
dw 512 dup(?)
sseg ends
code segment
assume cs:code,ds:data
start:
mov ax,seg strdec
mov ds,ax
circulate:
call enter
mov ah,9
lea dx,input1
int 21h
call inputdec
mov bx,ax ;第一个操作数在bx中//至此是正确的
call enter
mov ah,9
lea dx,input2
int 21h
call inputdec ;第二个操作数在ax中
xchg ax,bx ;第一个操作数在ax中,第二个操作数在bx中
call enter
call do
call enter
push ax
lea dx,strdec
mov ah,9
int 21h
pop ax
call outputdec
mov bx,ax ;bx为结果
call enter
push ax
lea dx,strhex
mov ah,9
int 21h
pop ax
call outputhex
call enter
push ax
lea dx,streight
mov ah,9
int 21h
pop ax
call outputeight
call enter
mov ah,9
lea dx,continue
int 21h
mov ah,1
int 21h
cmp al,'y'
je circulate
call enter
mov ah,4ch
int 21h
inputdec proc
push cx
push dx
push bx
mov dx,0dh
mov bx,0
mov ah,1
int 21h
cmp al,0dh
je decexit
cmp al,'-'
jne ok
mov dl,al
;若为负数,则输入下一个数字
p1: mov ah,1
int 21h
cmp al,0dh
je decexit
ok: sub al,30h
mov ah,0
xchg ax,bx
mov cx,10
mul cx
xchg ax,bx
add bx,ax
jmp p1
decexit:cmp dl,'-'
je negative
jmp done
negative:
neg bx
done: mov ax,bx
pop bx
pop dx
pop cx
ret
inputdec endp
outputdec proc ;以ax传递参数
push ax
push bx
cmp ax,0
jge next
neg ax
push ax
mov dl,'-'
mov ah,2
int 21h
pop ax
next:
mov bx,10
mov cx,0
again:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
ja again
output:
pop dx
or dl,30h
mov ah,2
int 21h
loop output
pop bx
pop ax
ret
outputdec endp
;十六进制的输出(0-ffff)*********************************************
outputhex proc ;以bx传递参数
push cx
push bx
;push ax;有了这句话,结果就不对了
temp dw ?
temp1 dw ?
mov temp,bx
mov temp1,bx
mov cl,8
shr temp,cl
mov bx,temp
call main1
and temp1,00ffh
mov bx,temp1
call main1
;pop ax
pop bx
pop cx
ret
main1 proc ;以
mov al,bl
mov cl,4
shr al,cl ;al内为高四位
cmp al,10
jb kk
add al,7
kk: mov dl,al
add dl,30h
mov ah,2
int 21h
and bl,0fh ;bl内为高四位
cmp bl,10
jb kk1
add bl,7
kk1: mov dl,bl
add dl,30h
mov ah,2
int 21h
ret
main1 endp
outputhex endp
;八进制的输出(0-ffff)--------------------ok
outputeight proc ;以bx传递参数
push cx
push bx
push ax
ttemp dw ?
ttemp1 dw ?
ttemp2 dw ?
cmp bx,0
jge next1
mov dl,31h
mov ah,2
int 21h
next1:
mov ttemp,bx
mov ttemp1,bx
mov ttemp2,bx
mov cl,9
shr ttemp,cl ;ttemp为bx的高7位的后6位
mov bx,ttemp
call main2
mov cl,3
shr ttemp1,cl
mov bx,ttemp1 ;ttemp1为bx的高13位的后6位
call main2
and ttemp2,7
mov dx,ttemp2
add dl,30h
mov ah,2
int 21h
pop ax
pop bx
pop cx
ret
main2 proc ;将bl的后6位输出两位八进制数
and bl,3fh
mov al,bl
mov cl,3
shr al,cl ;al内为高三位
mov dl,al
add dl,30h
mov ah,2
int 21h
and bl,7 ;bl内为低三位
mov dl,bl
add dl,30h
mov ah,2
int 21h
ret
main2 endp
outputeight endp
do proc;以ax传递参数
push dx
push ax
mov dx,offset input3
mov ah,9
int 21h
mov ah,1
int 21h
cmp al,'+'
jne ssub
pop ax
add ax,bx
jmp ddone
ssub:
cmp al,'-'
jne mmul
pop ax
sub ax,bx
jmp ddone
mmul:
cmp al,'*'
jne ddiv
mov dx,0
pop ax
mul bx
cmp dx,0
jmp ddone
ddiv:
;cmp al,'/'
;jne done
mov dx,0
pop ax
idiv bx
ddone:
pop dx
ret
do endp
enter proc
push ax
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop ax
ret
enter endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -