首页 > 解决方案 > My Sign flag value is showing wrong? Am I wrong about how sign flag works?

问题描述

I am adding ax and bx. So if MSB of the result is 1 then the sign flag=1 or else sign flag=0. Am I right? If I'm right why sign flag=0 is showing in output? Shouldn't it be SF=1? If I am wrong please correct me. I am confused

mov ax,20h
mov bx,80h
add ax,bx

标签: assemblyflagsemu8086

解决方案


因此,如果结果的 MSB 为 1,则符号标志 = 1,否则符号标志 = 0。我对吗?

您对反映结果最重要位的标志标志是正确的,但是在您的添加中,add ax, bx您添加了 2 个单词,这就是所有不同之处。

考虑添加字节

mov     al, 20h
mov     bl, 80h
add     al, bl     ; -> AL = 20h + 80h = A0h

结果设置AL了最高有效位(位 7),因此 SF=1

考虑添加单词

mov     ax, 0020h
mov     bx, 0080h
add     ax, bx     ; -> AX = 0020h + 0080h = 00A0h

结果中AX的最高有效位(第 15 位)被清除,因此 SF=0

小费

使用所涉及的寄存器可以容纳的尽可能多的数字写入十六进制数字可能会有所帮助。
mov ax, 0020h而不是mov ax, 20h.


推荐阅读