1.
TEST EAX,EAX
JNZ SHORT program.00407190
2.
XOR EAX,EAX
JNZ SHORT program.00407190
Kindly correct me if I'm wrong. Thank you! :)
From my understanding so far:
JNZ
is jump if not equal to zero, it will jump or not depending on whether ZF
is set to 1 or not. If it's 1, it will not jump. Else, it will jump.
From my understanding for code #1, TEST EAX,EAX
will check whether it's zero or not. If it's not equal to zero(ZF
is 0), it will jump to address 00407190.
For code #2 XOR EAX,EAX
will set EAX register to 0. Does it set any flags? If not, how does JNZ
instruction determine to jump or not?
Lastly, why would people want to check if EAX
is 0 or not? Kindly please assist me in a easier and detailed explanation, I'm still a beginner.
The JNZ instruction transfers control to the specified address if the value in the accumulator is not 0. If the accumulator has a value of 0, the next instruction is executed. Neither the accumulator nor any flags are modified by this instruction.
The XOR instruction performs a bit wise Exclusive OR operation between corresponding bits in the two operands and places the result in the first operand. reg, mem, and immed can be 8, 16, or 32 bits. The XOR instruction can be used to reverse selected bits in an operand while preserving the remaining bits.
In the x86 assembly language, the TEST instruction performs a bitwise AND on two operands. The flags SF , ZF , PF are modified while the result of the AND is discarded. The OF and CF flags are set to 0 , while AF flag is undefined.
the XOR (and many other arithmetic/logic operations) will set the zero flag of the status register if the result of the operation is zero.
TEST
and XOR
are logical instructions used to perform logical operations on the operands.
TEST INSTRUCTION (comparing the operands)
TEST destiny, source
It performs a conjunction, bit by bit, of the operands, but differing from AND
, this instruction does not place the result in the destination operand, it only has effect on the state of the flags.
Source Destiny | Destiny
--------------------------
1 1 | 1
1 0 | 0
0 1 | 0
0 0 | 0 <---
XOR INSTRUCTION (Exclusive OR)
XOR destiny, source
Its function is to perform the logical exclusive disjunction of the two operands bit by bit.
Source Destiny | Destiny
--------------------------
1 1 | 0 <---
1 0 | 1
0 1 | 1
0 0 | 0 <---
As you see in the tables:
XOR EAX,EAX
will set the EAX
register to zero. The ZF
will be set if the result of the XOR
is zero. So in this case: (ZF=1
)
TEST EAX,EAX
does not place the result on the register, it only has effect on the state of the ZF
. In this case if EAX == 0
, then (ZF=1
)
JNZ (JNE) INSTRUCTION (Conditional jump)
JNZ label
It jumps to label
if it is not equal or zero. The jump will be done if ZF
is deactivated. (ZF=0
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With