94 (5E in hex) + 183 (B7 in hex) = 277 (115 in hex), but because of the first cbw, AX = FFB7 instead of B7. However, the second number remains AX = 5E as expected, so adding the two results in AX = 15 with CF = 1. ... Why am I not obtaining 115 (hex)
The result depends on whether the values should be viewed as signed or unsigned.
For signed, you should fill the upper byte with the most significant bit of the lower byte. This can be done with the MOVSX
instruction (e.g. MOVSX AX,AL
) or with CBW
(CBW
only works if the operand is in AL
).
The byte 0xB7
sign-extended to a word equals -73
(0xFFB7
). So the expected result is 94 - 73 = 21 (0x15)
.
For unsigned, you should clear the upper byte. This can be done with the MOVZX
instruction (e.g. MOVZX AX,AL
) or by XOR:ing the upper byte with itself (e.g. XOR AH,AH
).
The byte 0xB7
zero-extended to a word equals 183
(0x00B7
). So the expected result is 94 + 183 = 277 (0x115)
.