当前位置:网站首页>Assembly: CPU structure - flag register and related instructions
Assembly: CPU structure - flag register and related instructions
2022-06-09 03:47:00 【Melon seeds 300g】
List of articles
One 、 summary
FLAG It's a computer terminology , Status flag register .
1、 The function of flag register
1、 be used for Storage Of relevant instructions Some data results .
2、 Used for CPU Execute relevant instructions Provide a basis for behavior .
3、 be used for control CPU Of How it works .
2、8086CPU Structure of flag register
The flag register functions bit by bit , Every one has a special meaning .
The characters marked in the above figure have special meanings , Other bits are not used ( Most of the effects are caused by operation instructions ( Logic / Count )).
3、debug Look at the flag bit
Before flag bit learning and verification , First, let's see how to debug Look inside at the sign .
Use command
-r
Print the results :
Print it out in the lower right corner of the screen NV UP EI PL NZ NA PO NC , These symbols represent the values of commonly used flag bits in the flag register .
OF <-----> OV(1) ; NV(0)
DF <-----> DN(1) ; UP(0)
IF <-----> EI(1) ; DI(0)
SF <-----> NG(1) ; PL(0)
ZF <-----> ZR(1) ; NZ(0)
AF <-----> AC(1) ; NA(0)
PF <-----> PE(1) ; PO(0)
CF <-----> CY(1) ; NC(0)
Two 、 Sign a
Flag bit classification :
1、 Operation result flag bit
2、 Status control flag bit : Used to control CPU Operation of the , They can only be changed by special instructions ). The status control flag bits are :TF、IF、DF.
Display the flag bit list
notes : The bold part is the status control flag bit
| Serial number | Logo name | Abbreviation | english | sign 1 | sign 0 |
|---|---|---|---|---|---|
| 1 | Overflow sign | OF | Overflow Flag | OV : overflow | NV : no overflow |
| 2 | Direction signs | DF | Direction Flag | UP : up | DN :down |
| 3 | Interrupt allow flag | IF | Interrupt-enable Flag | EI : enable interrupt | DI : disable interrupt |
| 4 | Tracking signs | TF | Trap Flag | ||
| 5 | Symbol sign bit | SF | Sign Flag | PL : plus | NG : negative |
| 6 | Zero mark | ZF | Zero Flag | ZR : zero | NZ : no zero |
| 7 | Auxiliary carry flag | AF | Auxiliary Carry Flag | AC : assistant carry | NA : no assistant carry |
| 8 | Parity mark | PF | Parity Flag | PE : parity even | PO : parity odd |
| 9 | Carry mark | CF | Carry Flag | CY : carry | NC : no carry |
1、CF(0): Carry flag bit
Indicates whether the highest bit in addition and subtraction operation has a forward position / Borrow position .
If there is no carry in the operation / Borrow position :CF == 0( Show as NC)
If the operation has a carry / Borrow position :CF == 1( Show as CY)
2、PF(2): Parity flag bit
Record the execution of relevant instructions , Of all the bits of the result 1 Whether the number of is even .
When all binary bits are 1 The number of is odd :PF == 0( Show as PO)
When all binary bits are 1 The number of is even :PF == 1( Show as PE)
3、AF(4): Auxiliary carry flag
stay 8 Bit addition and subtraction operation indicates low 4 Set high 4 Whether the position is advanced or not / Borrow position .
No progress / Borrow position :AF == 0( Show as NA)
There is progress / Borrow position :AF == 1( Show as AC)
4、ZF(6):0 Sign a
Indicates that the result of the operation is 0 Or not 0.
When the result of the operation is not 0:zf == 0( Show as NC)
When the result is 0:zf == 1( Show as CY)
5、SF(7): Symbol sign bit
Indicates that the result of the operation is negative ( The highest bit is 1) Or nonnegative ( The highest bit is 0)
When the result is nonnegative :SF == 0( Show as PL)
When the operation result is negative :SF== 1( Show as NG)
6、TF(8): Tracking signs
When tracking signs TF == 1 when ,CPU Enter single step execution mode .
7、IF(9): Interrupt flag bit
Express CPU Can I respond to maskable interrupt requests .IF The status of has no effect on non maskable interrupts and internal interrupts .
8、DF(10): Direction sign bit
Indicates that the string operation is performed in the way of address subtraction or addition .
Every operation si di Increasing :df == 0 ( Show as UP)
Every operation si di Decline :df == 1 ( Show as DN)
9、OF(11): overflow flag
( Signed operations ) overflow flag : When performing signed operations , If the result exceeds the range indicated by the machine , It's called overflow .
8 The range of bit signed numbers is -128 ~ +127,
16 It is -32728 ~ +32767).
If there is no overflow :OF==0( Show as NV)
If there is an overflow :OF == 1( Show as OV)
3、 ... and 、 Instructions
1、adc: Add
Add instruction with carry , utilize CF Value on
Instructions :adc ax,bx
Calculation :ax = ax + bx + CF
2、sbb: Subtraction
sbb It's a subtraction instruction with borrow , utilize CF Value on
Instructions :sbb ax,bx
Calculation :ax = ax - bx - CF
3、cmp: Compare
cmp It's a comparison command ,cmp The function of is equivalent to the subtraction instruction , Don't save results , But it affects the flag register .
Instructions :cmp ax,bx
Calculation : ax - bx Set the flag register input according to the calculation result .
Such as execution :
mov ax,8
mov bx,3
cmp ax,bx
After execution :(ax)=8, zf=0, pf=1, sf=0, cf=0, of=0
4、 The conditional transfer instruction that detects the comparison result
| Instructions | meaning | Relevant flag bits detected |
|---|---|---|
| je | If it is equal to, it will be transferred | ZF=1 |
| jne | If not, transfer | ZF=0 |
| jb | Lower than, transfer | CF=1 |
| jnb | No less than, then transfer | CF=0 |
| ja | If it is higher than, it will be transferred | CF=0 And ZF=0 |
| jna | If it is not higher than, it will be transferred | CF=1 or ZF=1 |
5、pushf、popf: Push 、 Out of the stack
pushf: Stack the flag register value
popf: Pop data from stack , Enter the flag register
边栏推荐
- Data: Kube flannel and kubernetes dashboard creation commands and configuration file contents
- 【5月考试】ORACLE OCP 19C 通过
- After 15000 interns joined Amazon, what was life like in the big factory?
- Research on MySQL open source license
- [examination in May] Oracle OCP 19C passed
- 关于回调的一些思考
- Don't hand in the paper in advance!!! Someone got 13 points in the last 35 seconds!!! (best wishes to all candidates)
- 故障分析 | DDL 导致的 Xtrabackup 备份失败
- Final assignment of Web Design - website of XXX company (including navigation bar, rotation chart, etc.)
- Handling of missing data in ArcGIS runtime offline GDB
猜你喜欢

Fault analysis | a special scenario in MySQL where a new user cannot log in

Five highlights of wwdc2022 lock screen, weather kit, swiftui, collaboration function, apple payment

Today in history: kubernetes open source version released; Worldofwarcraft landed in China; The inventor of packet switching network was born

Calculation method and comparison steps of target detection model map -- compare the map between the original model and the quantitative model

Getting started with Maui custom drawing

opencv学习笔记一

Why common read SQL is sent to the master instance in the distributed dble read / write separation scenario

MAUI 自定义绘图入门
![[share] network packet loss fault handling scheme](/img/40/39e6548651eaeec5e6c1c39651cc88.png)
[share] network packet loss fault handling scheme

接口性能测试:web service接口测试
随机推荐
汇编:jmp指令
[play with Huawei cloud] functions and features of Kunpeng code migration tool
How to calculate the number of parameters in the LSTM layer
【5月考试】ORACLE OCP 19C 通过
Tips for using idea
Fault analysis how the MySQL database gets stuck after upgrading
Mongodb database document display exception
软件工程期末考试试题及答案(详细、经典)
[reinforcement learning notes] V value and Q value in reinforcement learning
基于FPGA的VGA显示彩条、字符、图片
【分享】网络丢包故障处理方案
Concurrent operation -- the difference between reentrantlock and synchronized
National Natural Science Foundation Project query website
SQL audit | here are the most commonly used SQL development rules for mysql/oracle
Controversial Xu Beihong's paintings and the copyright dispute of Digital Collections
C#.net调用动态库dll注意事项
JS逆向字体反爬,某供应商平台反爬实践
GC log analysis
不要提前交卷!!!曾有人在最后35秒,拿到了13分!!!(祝所有考生顺利)...
月薪近万,3年销售助理转行测试,0经验的我如何拿到多份offer?