我的一项家庭作业练习如下:
mov al,77h
sub al,80h
AL=_______
CF=_______
OF=_______
当我第一次看到它时,我认为正数减去正数的结果不会溢出。而我的OF等于0 但是我的汇编代码向我显示OF = 1。
我正在使用32位控制台环境MASM6.15
这是我的代码和输出:
代码1:
; eg000000.asm in Windows Console
include io32.inc
.data
.code
start:
mov al,77h ;119
sub al,80h ;128
call disprf ;show those 6 flags
call dispbd ;binary
call dispcrlf
call disphd ;hexadecimal
exit 0
end start
输出1:
OF=1, SF=1, ZF=0, AF=0, PF=0, CF=1
000000000001100111111111 1111 0111
0019FFF7
代码2:
; eg000000.asm in Windows Console
include io32.inc
.data
.code
start:
mov al,77h
add al,-80h ;-128
call disprf
call dispbd
call dispcrlf
call disphd
exit 0
end start
输出2:
OF=0, SF=1, ZF=0, AF=0, PF=0, CF=0
000000000001100111111111 1111 0111
0019FFF7
代码3:
; eg0000.asm in Windows Console
include io32.inc
.data
.code
start:
mov al,77h
sub al,7fh ;127
call disprf
call dispbd
call dispcrlf
call disphd
exit 0
end start
输出3:
OF=0, SF=1, ZF=0, AF=1, PF=0, CF=1
000000000001100111111111 1111 1000
0019FFF8
在“代码1”中,我希望OF = 0和CF = 1
在“代码2”中,我期望CF = 1
“代码3:”的输出正确
有人可以告诉我为什么吗,如果在计算机完成计算之前立即数超出“代码1”之类的范围怎么办。我知道,无论有符号或无符号数字,计算机都不知道。
顺便说一句:我的第一个问题在这里。如果我做错了什么,如果您能指出并告诉我正确的做法,我将不胜感激。:)
答案 0 :(得分:0)
80h
位模式的带符号2的补码解释为-128
。这对于sub
如何设置OF很重要。另请参见Understanding Carry vs. Overflow conditions/flags for signed vs. unsigned.
-80h
是相同的值,并将汇编为相同的机器代码。