【发布时间】:2021-08-29 04:05:03
【问题描述】:
代码在这里,我的电脑是x86。这段代码的功能是十六进制到十进制的转换,但是还没有完成。现在它只是将数字放入堆栈。
ASSUME cs:code,ds:data
data SEGMENT
ENDS
code SEGMENT
start:
mov ax,data
mov ds,ax
mov bx,19 ;the number needed to be output as decimal format is saved in bx
call output
mov ah,4CH
int 21H
output proc
mov ax,bx ;the number that needed to be output is saved in bx , now move it to ax
mov bx,10
mov cx,0 ;use cx to record how many figure needed to be output
division:
mov dx,0
div bx
push dx; save the remainder in stack
inc cx
cmp ax,0
jne division ;if the ax is not zero,means still need ax still need to be divided
ret
output endp
code ENDS
end start
【问题讨论】:
-
push dx; save the remainder in stack- 那是ret返回的地方。 -
在执行
output函数的ret之前,需要清理堆栈,使ss:sp再次指向返回地址。您必须运行许多pop指令才能实现此目的。 -
非常感谢,完美解决问题。