3

I'm trying to reverse engineer a program and i found the following instruction:

test al, al
je label 

what does these two instruction do ? Can someone explain please ?

2
  • test equals and but does not place the result in the target operand. However, like and it manipulates the zero flag (ZF).
    – 0xC0000022L
    Commented Jun 1, 2020 at 19:36
  • 2
    This is a standard idiom to test if the 8-bit value stored in AL (the register that is the low 8 bits of EAX) is zero. In other words, it's checking whether a Boolean is true or false, and branching accordingly.
    – Cody Gray
    Commented Jun 2, 2020 at 3:17

1 Answer 1

13

In x86 assembly, al is the least significant byte of eax register, which is typically used to return values from function calls.

The test al,al is a bitwise AND operation between al and itself.

If al & al == 0, the zero flag will be set to 1.

je (or jz) instruction will jump to the address of label, if the zero flag is 1. Otherwise, the je will do nothing.

In short: If eax == ######00 jump to label.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.