Hello and welcome.
In this lesson, we are going to study how the AND, OR, and XOR instructions affect the flags, particularly
the zero flag,
the sign flag.
Now for all three instructions,
it does not affect the overflow flag or the carry flag, but it affects or modifies the sign flag or
the zero flag depending on the value that is the result of the execution.
So let's take a look at a practical example.
Now we are going to use the x64dbg.
I have loaded the template 2x into x64dbg.
So let's go to our code here and enter this value.
Hit
okay.
Now we are going to AND this value with zero.
So this value converts into 0x88.
So we can confirm that by using our programmer's calculator.
If we enter, we set this to byte.
And here we set this hex to 88.
And we can see that in binary it is 10001000, which is this number here.
So now we are going to AND this number with a zero.
So the result will be stored back into -.
And the result should be zero.
Because when you AND anything with zero, you get back a zero.
So because the result's most significant bit is zero, it will be interpreted as a positive number.
So since it is interpreted as a positive number, the sign flag will be cleared.
And then because the result is zero, the zero flag will be set.
So let's step into it now.
We run to our breakpoint.
Step over.
And we see that indeed the zero flag is set, but the sign flag is clear.
Next, we will take a look at the OR example.
So we will move this value into -.
So let's move into -.
Next, we are going to OR with all ones.
So what do you expect to get?
So what you get is after this operation is that the result will be non-zero.
So non-zero means that the zero flag will be cleared, because the significant bit is going to be one.
Therefore, the sign flag will be set because it will be interpreted as a negative number.
So let's step over that now.
And indeed, we see zero flag is cleared and the sign flag is set.
Okay, for the last one, we are going to XOR -.
So let's try that now.
When you XOR, the result will always be zero.
So what do you expect to see in zero flag,
sign
flag?
Let's run and see.
So zero flag is set because the result of a XOR on the register with itself will always be a zero,
and the sign flag is set to zero because the result is zero.
Therefore, the most significant bit is zero, meaning that it is a positive number.
So the sign flag is zero. So only if it's a negative number, the sign flag will be set; otherwise, it
will be zero.
And as we have studied before, whether or not the number is positive or negative depends on the
most significant bit.
If the most significant bit is one,
then it is interpreted as a negative number and the sign flag will be set.
However, if the most significant bit is zero, it will be interpreted as a positive number and the
sign flag will be cleared.
So that's all for this video.
Thank you for watching.