| |

VerySource

 Forgot password?
 Register
Search
View: 34|Reply: 4

A question about the flag of the signpost?

[Copy link]

2

Threads

4

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-1-23 01:40:01
| Show all posts |Read mode
After executing the following program: ax =?
mov ax, 0
push ax
popf
mov ax, 0fff0h
add ax, 0010h
pushf
pop ax
and al, 11000101B
and ah, 00001000B

When the program finishes adding ax, 0010h,
Why is the flag register like this? ?
cf of sf zf pf
1 0 0 1 1

Instead of
cf of sf zf pf
1 1 0 0 0
Reply

Use magic Report

0

Threads

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 China

Post time: 2020-2-9 01:00:01
| Show all posts
0fff0h + 10h = 0 So, zf = 1 (result is 0), sf = 0 (result is non-negative), pf = 1 (result is even 1)
During the operation, a carry was generated, so cf = 1. Negative numbers + positive numbers, of course, the result will not overflow, so of = 0
Reply

Use magic Report

0

Threads

9

Posts

6

Credits

Newbie

Rank: 1

Credits
6

 China

Post time: 2020-2-11 11:30:01
| Show all posts
mov ax, 0fff0h
add ax, 0010h
--------------------------------
It turned out to be 10000h! 16-bit, it should have overflowed!

Because this is the value of ax (the low order of 10000h) and 0000h, it is zero. zf == 1, and at this time, "1" in the value of ax is 0, which is an even number, so pf == 1, and because of borrowing, so cf == 1, but it is impossible to understand of Difficult because of the 32-bit problem? The carry is stored in the high position of eax, so is of == 0? ? ? ?
Reply

Use magic Report

0

Threads

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 China

Post time: 2020-2-13 17:00:02
| Show all posts
Overflow and carry are different concepts. Overflow is for signed numbers, and overflow occurs when the result is outside the range of representation.
As a signed number, 0fff0h = -16, 10h = 16, -16 + 16 = 0, completely within the range of a 16-bit signed number, so no overflow occurs, 0f = 0

Carry is an unsigned number.Likewise, the result occurs when the result is out of range.

For the same operation, different flags are set in order to take each of the subsequent discrimination.
Reply

Use magic Report

2

Threads

4

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

 Author| Post time: 2020-6-21 21:15:01
| Show all posts
Thank youwww_james
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list