我已经评论了错误的地方,需要修复:
format MZ
entry code_seg:start
stack 256
segment data_seg
; Add carriage reurn and line feed to ut output on seprate lines.
o_set db "Overflow flag set", 13, 10, "$"
o_notset db "Overflow flag not set", 13, 10, "$"
segment code_seg
start:
push bp
mov bp, sp
mov ax, data_seg ; We must set up the DS register by pointing
; at the segment with our data
mov ds, ax
test ax, ax ; Make sure overflow flag is cleared
; Not guaranteed when our program starts
mov cl, 99
jo of_flag_set ; You jumped to the wrong label when overflow was set
push o_notset
call printf
add sp, 2
add cl, 98
jo of_flag_set
jmp endme
of_flag_set:
push o_set
call printf
add sp, 2
endme:
mov sp, bp
pop bp
mov ah, 0h
int 20h
; Need to put offset to msg on stack prior to call. Stack cleaned up by callee
printf:
push bp
mov bp, sp
mov dx, [bp+4] ;cant pop the retn addr into dx
mov ah, 09h
int 21h
mov sp, bp
pop bp
ret
您的字符串没有正确打印(它们在屏幕上被移动),因为您没有设置
DS公司
(数据段)寄存器。创建DOS MZ(EXE)程序时,需要显式移动数据区域的段位置
data_seg
到
DS公司
. 因为您没有这样做,所以字符串从错误的位置打印出来。
我在字符串中添加了回车符和换行符,以便它们在单独的行上打印。
您的代码不能依赖于在程序启动时清除溢出标志。你需要使用一个指令来清除它。
test ax, ax
如果你不介意改变其他标志的话,就可以了。
你的一个
jo
当检测到溢出时,它指向错误标签的说明。