I am currently trying to deepen my understanding of assembly code and I am stuck since weeks with a seemingly simple instruction :
sub al, BYTE PTR [ebp+4]
Assuming eax = 0x11223300
and BYTE PTR [ebp+4] = 0xaa
what is the value of eax
after the above instruction ?
From what I understand, al
can only affect the last byte in eax
(0x00
in this case) so the program tries to compute 0x00 - 0xaa
. But the result being negative, I don't get if the result would simply be 0x00
or if numbers are automatically transformed to a negative number, in which case 0xaa
can itself be considered as a negative value which would imply we are trying to compute 0x00 - (-0x2a)
= 0x2a
I found in the SUB documentation that
The SUB instruction performs integer subtraction. It evaluates the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate an overflow in the signed or unsigned result, respectively. The SF flag indicates the sign of the signed result.
But it only describe some behaviour of the flags and I can't figure out how to look for more about those in such a specific case.