I'm doing a crackme to learn some reversing, and I stumbled upon this code generated by C++ MFC:
sbb eax, eax
sbb eax, -1
test eax, eax
jz exit
Before that code a comparison is done, such as cmp al, bl
where al and bl hold some value read from the serial
The thing that confused me, is I figured that the cmp and two sbb instructions are equivalent to this pseudocode:
cmp a,b
eax=-1 if b>a
eax=1 otherwise
However this confused me because eax can never be 0, so the zero flag will always be set. Therefore, I figure the chunk of code
test eax, eax
jz exit
is useless because it does nothing- but how can this be? I don't think their C++ compiler would generate useless code like that
Where am I wrong here?
sbb
? – Igor Skochinsky♦ Jul 25 '16 at 7:39