Using AT&T assembly syntax, I’m trying to understand how testl is used in assembly code. Specifically:
testl %edx, %edx
jle .L3
I know testl does a bitwise and of the same value to set the condition flags, but how can I interpret ‘jump if less than or equal to’ if it isn’t comparing two values?
Here’s an excerpt from the official documentation from Intel on test:
And the same on jle:
So, the jump will be performed if
edxis 0 (becauseedx AND edx = edxand that’s 0 only whenedxis 0, and becauseZFis set to 1 when the result ofANDis 0) or if the most significant bit ofedxis 1 (becauseSF = most significant bitofedx AND edx(or, equivalently, ofedxitself) andOFis always 0, which meansSF ≠ OFis only true whenSF ≠ 0).IOW, the jump will be performed only if
edxis ≤ 0 when interpreted as a signed integer or, equivalently, whenedxis either 0 or greater or equal than 0x80000000 when interpreted as an unsigned integer.