当前位置:网站首页>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

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

 Please add a picture description 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 :
 Please add a picture description 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 OFOverflow FlagOV : overflowNV : no overflow
2 Direction signs DFDirection FlagUP : upDN :down
3 Interrupt allow flag IFInterrupt-enable FlagEI : enable interruptDI : disable interrupt
4 Tracking signs TFTrap Flag
5 Symbol sign bit SFSign FlagPL : plusNG : negative
6 Zero mark ZFZero FlagZR : zeroNZ : no zero
7 Auxiliary carry flag AFAuxiliary Carry FlagAC : assistant carryNA : no assistant carry
8 Parity mark PFParity FlagPE : parity evenPO : parity odd
9 Carry mark CFCarry FlagCY : carryNC : 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

原网站

版权声明
本文为[Melon seeds 300g]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090338385042.html