Drip Reverse Notes (6. Flag Register)

one.

1. Pushad

Comparing the above two figures, we can see that the function of pushad is equivalent to storing the values ​​of the eight general-purpose registers in the upper memory unit in sequence, the memory number corresponding to the bottom of the stack remains unchanged, and the memory number corresponding to the top of the stack is also changed from the original 7c changed to 5c

I don’t know what to say about this, so I just compare the two pictures to summarize

2.popad

The memory number corresponding to the register here has also been slightly changed, let’s see the effect next.

Here you can see that it restored the memory numbers corresponding to the 8 registers before pushad was executed, but the values ​​stored in the involved memory units did not change back

2. (Note: The mov instruction does not affect the flag register)

1. Carry flag CF: If the highest bit of the operation result generates a carry or borrow, then its value is 1, otherwise, its value is 0

Here add al, 1 has not been executed yet, it is now c0

After the execution here, c0 becomes c1 at this time

At this time, eax is not 11120100 but 11120000. The answer given by the teacher here is that the one who entered has entered c0

2. Parity flag PF: The parity flag PF is used to reflect the parity of the number of "1" in the operation result. If the number of "1" is even, the value of PF is 1, otherwise its value is 0 (note: The number of "1" here is the least significant byte, that is, the last two bits)

                                                                  

First execute the mov al,3 instruction, then we will execute add al,3

 At this time, it can be found that p0 has become p1, and converted into binary 0011 becomes 0110, two "1", even number, so at this time p0 becomes p1, and then we will execute add al,2

 After the instruction is executed, 0110 becomes 1000, at this time there is only one "1", and p1 becomes p0

3. Auxiliary carry flag AF: In the following cases, the auxiliary carry flag AF is set to 1, otherwise it is 0

(1) During word operation, when a carry or borrow occurs from the low byte to the high byte;

(2) During byte operation, when a carry or borrow occurs from the lower 4 bits to the upper 4 bits;

Just finished executing the mov ax,0x5efe instruction, then

After executing add ax,2, it can be seen that A0 becomes A1

4. Zero flag: The zero flag is used to reflect whether the operation result is 0, if so, its value is 1, otherwise it is 0

Next, execute sub eax, eax

At this time, the operation result is 0, and Z0 becomes Z1

5. Sign flag SF: SF is used to reflect the sign bit of the operation result, which is the same as the highest bit of the operation result

Just finished executing mov al,7f, then

 After executing add ax,2, from the binary point of view, it has changed from 0111 1111 to 1000 0001, and S0 has become S1

6. Overflow flag OF: The overflow flag is used to reflect whether the result of signed number addition and subtraction overflows. If the overflow result exceeds the range that can be represented by the current number of digits, it is called overflow, and the value of OF is set to 1, otherwise is 0

The difference between the highest bit carry and overflow:

The carry flag indicates whether the unsigned operation result is out of range

The overflow flag indicates whether the signed number operation result is out of range

Unsigned number: 0~FF,

                                                     Signed number: positive number 0~7F, negative number: 80~FF

Overflow is mainly used for signed operations. In signed operations, there are the following rules:

Positive + positive = positive, if the result is negative, there is an overflow

Negative + negative = negative, if the result is positive, then there is an overflow

Positive + Negative never overflows

(1) When neither unsigned nor signed numbers overflow

At this time, mov al,7 has just been executed, and then

After executing add al,7, you can see that C0 and O0 have not changed

(2) When unsigned numbers overflow and signed numbers do not overflow

Just finished executing mov al, 0xff, then

After executing add al,2, it is found that only C0 becomes C1 at this time, and O0 remains unchanged

(3) Unsigned numbers do not overflow, signed numbers overflow

At this time, mov al,7f has just been executed, and then

 After executing add al,2, C0 remains unchanged, O0 becomes O1

(4) When both signed and unsigned numbers overflow

Just finished executing mov al,0x80, then

After executing add al,81, you can see that C0 and O0 have become C1 and O1 respectively

Guess you like

Origin blog.csdn.net/m0_51295934/article/details/122585169