王爽《汇编语言》实验10中的dtoc子程序,运行不了,但是单步调试可以通过并且结果正常,我的代码如下:
assume cs:code
data segment
db 10 dup (0)
data ends
code segment
start:
mov ax,12666
mov bx,data
mov ds,bx
mov si,0
call dtoc
mov dh,8
mov dl,3
mov cl,2
call show_str
mov ax,4c00h
int 21h
dtoc:
; (ax)=w data, ds:si=first address of str
mov cx,5
mov bx,10
mov di,0
s0:
div bx
add dl,30h
mov [di],dl
inc di
mov dx,0
loop s0
ret
show_str:
; (dh)=line_num (0~24), (dl)=column_num (0~79)
; (cl)=color, ds:si=source address
mov ax,0b800h
mov es,ax
mov al,dh ; calculate the address
mov ah,0
mov dh,80
mul dh
mov dh,0
add ax,dx
add ax,ax
mov bx,ax
mov al,cl ; store the color
mov cx,0
s:
mov cl,[si]
jcxz show_str_ret
mov es:[bx],cl
inc bx
mov es:[bx],al
inc bx
inc si
loop s
show_str_ret:
ret
code ends
end start
单步调试正常:
求助大佬!!😫
知道原因了,dosbox除法溢出竟然不会引起中断。我在virtualbox的dos系统上试了试,结果提示了divide overflow,但是在dosbox上运行就是直接卡住。。。
除法溢出的原因是在对bx做16位除法之前没有把dx设成0,导致除法溢出;在debug中之所以可以,是因为debug启动的时候会先对寄存器进行初始化,也就是说debug帮我把dx设成了0。