Hello and welcome back.
In this lesson, we are going to study the carry flag.
-, so let's try to put some value in -.
Before that, let us run to our breakpoint.
We are using template two.
Step over until you reach this line.
So let's try to perform an operation using -.
That means the first byte. Right-click on the - register, modify, and set it to ten in hex.
So now we are going to perform an arithmetic operation.
We are going to add one to -.
Add -, one.
So notice the carry flag.
Carry flag should not be set because the size of the
- is a maximum size, 255.
So it should be able to store the value of the operation.
So let's step over this,
and you notice that the - flag is not set.
So you managed to increase it by one.
So it's 11.
So maximum is 255. 255 in hex is FF.
So in this case, it doesn't exceed FF.
Therefore, the carry flag is not set.
So now let's try to perform an operation which will increase the value beyond 255.
So let's try to add -, 255 itself.
So now you're going to add this FF with this 255.
And you step over, and you see now the carry flag is set because the size of the - register is too small
to store the result of the addition.
That's why you see carry flag is set, indicating that there is an error.
Okay.
Now let's study the subtraction.
For that, we will use the - register.
- register now is one.
Let's try to subtract one from it.
So let's subtract -, one, and see what happens.
Step over that,
and you see carry flag is cleared because the size of the register is sufficient for doing the
subtraction.
So now let's try to minus another big number from -, see what happens.
Subtract, maybe minus ten from -.
And we step over, you see,
carry flag is set.
This is because the - flag only captures the unsigned numbers
operation.
So in this case, it cannot store negative numbers.
- only captures the error for unsigned numbers.
So because when you minus one from zero, it is already a negative number.
So negative number cannot be stored in the - register.
That's why it shows as a carry flag set to one.
So that's how the - flag is used in the assembly.
So that's all for this video.
Thank you for watching.