Chapter 13 Flag Register (X86 Assembly Tutorial)

Publisher:TranquilWhisperLatest update time:2015-05-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Actually, the content of this chapter is not that important. It doesn't matter if you don't understand it. These are all processed by the background. Few people operate the flag register by themselves. It's like you don't know how many times your heart beats per minute, but you are still alive and well. In addition, someone actually reposted a certain chapter before, although I didn't write that chapter and can't repost it...

     This chapter briefly introduces a register. It paves the way for the following chapters (because I am a lazy person, I have not decided when to write the next chapter.)

    The flag register (PSW) is used to save the calculation results and certain states of the CPU.

    In order to achieve some functions, when the CPU executes certain instructions, it will save some of the calculation results to the flag register, which are generally arithmetic instructions. For example, whether the calculation result is positive or negative.

    The 186 flag register is 16 bits. Except for a few unused bits, each bit has a different meaning and name. The name table is as follows:

  15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 |00
  [   ][     ][     ][    ][OF][DF][IF  ][TF ][SF][ZF][     ][AF][     ][PF][     ][CF]

 

 

[Bit 0 CF]
This is used to record the bit of data that exceeds the bounds after the relevant instruction is executed.
For example:
when adding:
mov ah,10000000B
mov al,10000000B
add ah,al
Result: ah=00000000B (theoretically there is a 1 in the 9th bit, but ah is an 8-bit register, so the 9th bit is not placed here)
The 9th bit is placed in CF!

When performing subtraction, the value borrowed from the high bit can be calculated:
mov ax, 0000H
sub ax, 0001H
Result: ax = FFFFH (a number is borrowed from the 17th bit, so CF = 1 (indicating a borrow!), if no number is borrowed, CF = 0)
[The second bit PF]
is used to record whether the number of 1s in all bits of the result after the execution of the relevant instruction is an even number, if it is, PF = 1 otherwise PF = 0
[The sixth bit ZF]
is used to record whether the result of the execution of the relevant instruction is 0, if it is 0, ZF = 1 otherwise ZF = 0, for example:
mov AX, 1
sub AX, 1
The result is 0, then ZF = 1
Instructions that affect flag bits, such as add, sub, mul, div, inc, or, and, etc., are mostly calculation instructions, and some have no effect, such as mov, push, pop, etc., most of which are transfer instructions.
[The seventh bit SF]
records whether the result after the instruction is executed is a negative number, if it is a negative number, then = 1 otherwise = 0
[8th bit TF]
If TF=1, the CPU will generate an interrupt after running a line of code. If it is 0, the code will continue to run.
[9th bit IF]
Controls whether to respond to external interrupts. If it is 1, it will respond. If it is 0, it will not respond. The STI instruction can set it to 1, and the CLI instruction can set it to 0.
[10th bit DF]
For some instructions...
[11th bit OF]
Overflow flag. If the calculation result overflows, OF=1, otherwise OF=0
Overflow example:
mov ah,FFh
add ah,FFh
The calculation result is greater than the maximum value that ah can store, and it will overflow.
 

 End of this chapter..

Reference address:Chapter 13 Flag Register (X86 Assembly Tutorial)

Previous article:Chapter 15 XOR and NOT (X86 Assembly Tutorial)
Next article:Chapter 11 Stack (X86 Assembly Tutorial)

Recommended ReadingLatest update time:2024-11-16 17:51

Chapter 1 From Machine Code to Development Language (X86 Assembly Tutorial)
It is difficult to remember something if you don't practice it, so you don't need to understand the first few chapters too much, just take a look at them. When you practice, you will gradually master them by occasionally flipping through them. Remember: I am not saying that the previous knowledge is not important, but
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号