Assembly Language Tag register mark bit _nv up EI NG NZ AC PE CY

Source: Internet
Author: User
Tags processing instruction

In 8086CPU, there is a marker register with a length of 16bit;

The information stored here is called the program status Word, thePSW, and the Register is abbreviated as flag.

Function: 1) used to store some execution results of related instructions;

2) to provide the basis for the implementation of the relevant instructions for the CPU;

3) to control how the CPU works.

Flag Register Everyone

Note: 16 characters not marked in the 8086CPU are not used, meaningless;

The characters are marked with a special meaning.

Bit symbol English full name description (mathematical or logical operation)

0 CF Carry flag carry flag bit unsigned number operation result whether carry/borrow

2 PF Parity flag Parity operation result binary indicates the number of members 1 (odd-even representation)

4 AF auxiliary carry flag auxiliary carry marker bit af=1, carry or borrow to high or higher byte

6 ZF Zero Flag 0 operation result of 0

7 SF sign flag symbol Mark bit signed number operation result positive and negative

8 TF Trap flag trace flag bit tf=1, resulting in a single-step interrupt, triggering the interrupt process

9 IF interrupt-enable flag interrupt allow Mark bit if=1/0,cpu allow interrupt or shutdown interrupt

DF Direction Flag Direction marker bit string processing instruction DF=0/1, controlling the increment or decrease of si,di per operation

One of Overflow flag overflow flag bit signed number operation result overflow

Note: Mathematical or logical operation instructions will affect flag, including add,sub,mul,div,inc,dec,or,and, etc.;

Mov,push,pop and other delivery instructions have no effect on flag;

TF trace flag (set for debug machine or Debugger discovery failure):

Tf=1,cpu the execution of an instruction will cause a single-step interrupt, and go to execute interrupt handler;

The TF=0,CPU is in continuous working condition.

If interrupt allows the mark bit (can mask interrupt interrupts during CPU detection if determine if masking interrupts):

If=1,cpu after executing the current instruction, the response is interrupted and the interrupt process is triggered;

IF=0,CPU does not respond to interrupts after executing the current instruction.

STI, then if=1;

CTI, then if=0.

Detailed description of each register reference: http://www.cnblogs.com/ant-colonies/p/6008322.html

The representation of the tag register in debug
ax=0000 bx=0000 cx=0000 dx=0000 sp=ffee bp=0000 si=0000 di=0000
ds=**** es=**** ss=**** cs=**** ip=0100NV up EI PL NZ NA PO NC
The bit flag value is1The flag value is0The logo
0 CF CY (CarrY) NC (not CarrY)
2 PF PE (Parity even) PO (Parity Odd)
4 AF AC (auxiliary Carry) NA (No auxiliary Carry)
6 ZF ZR (zero) NZ (not zero)
7 SF NG (negative) PL (Positive)
9 IF DI (Disabled Interrupt) EI (inabled Interrupt)
DF DN (down) up (UP)
One of OV (Overflow) NV (not Overflow)

Mark Bit CF with of:

ADC is an addition instruction with carry
Instruction format: ADC OBJECT1,OBJECT2
Function: OBJECT1=OBJECT1+OBJECT2+CF
Example: ADC ax,bx (AX) = (AX) + (BX) +CF

SBB is a subtraction instruction with borrow.
Instruction format: SBB Object1,object2
Function: OBJECT1=OBJECT1-OBJECT2-CF
Example: ADC ax,bx (AX) = (AX)-(BX)-CF

Note: ADC and SBB can be used to solve the problem that the carry cannot be stored when the add,sub operation;

ADC (add & CF), with carry addition;

SBB (Sub & below), with misplaced subtraction;

The comparison of the CF with the of the mark bit:

1111 1111 8bit indicates that the range corresponding flag bit is out of range
2^8-1 (255) unsigned number [0,255] CF takes place or borrow to a higher position
2^7-1 (127) signed number [ -128~127] of overflow

CMP directives
Instruction format: CMP OBJECT1,OBJECT2
Function: Calculates the Operation Object Object1-object2, but does not save the result, only sets the flag register according to the calculation result
Example:
CMP Ax,ax; (comparison of unsigned numbers)
After executing ax value unchanged, zf=1,pf=1,cf=0,of=0;
MOV ax,8
MOV bx,3
CMP AX,BX
After execution: (AX) =8,zf=0,pf=1,cf=0,of=0.


Instruction CMP AX,BX(comparison between unsigned numbers, reference mark bit ZF,CF)
Zf=1, then (ax) = (BX)
Zf=0, then (AX)! = (BX)
Cf=1, then (AX) < (BX)
Cf=0, then (AX) >= (BX)
Cf=0 and Zf=0, then (AX) > (BX)
Cf=1 or Zf=1, then (AX) <= (BX)

Instruction CMP AH,BH(comparison between signed numbers, reference mark bit SF,OF,ZF)
Sf=1, and of=0, then (AH) < (BH)
Sf=1, and Of=1, then (AH) > (BH)
Sf=0, and Of=1, then (AH) < (BH)
Sf=0, and of=0, then (AH) >= (BH)

Conditional Transfer directives:
The essence of "transfer" is to modify the IP; Condition "refers to the ability to determine whether an IP is modified according to a condition
The transfer displacement range for all conditional transfer directives is [-128,127]
1) Jcxz, that is, when (CX) =0, that is, modify the IP (implement transfer)
2) The CMP directive affects the mark register mark Bit and is used in conjunction with the following conditional transfer directives
A commonly used conditional transfer directive that transfers based on the comparison of unsigned numbers:
directive meaning detection related flag bit
Je equals the transfer zf=1
Jne is not equal to transfer zf=0
JB less than then transfer cf=1
JNB is not less than the transfer cf=0
JA is greater than transfer cf=0 and zf=0
JNA not greater than transfer cf=1 or zf=1

Note: j-jmp
E-equal Ne-not Equal
B-below Nb-not Below
A-above Na-not above

Mark bit DF with string transfer instructions:


DF (Direction flag), directional sign, controls the increase or decrease of si,di after each operation
Df=0,si,di Increment
Df=1,si,di Descending
String Transfer instructions:
Format:MOVSB; MOV string byte
Function: 1) ((es) *16+ (di)) = ((ds) *16+ (SI))
ie: mov es:[di],byte ptr ds:[si]
2) when df=0, (si) = (si) +1
(di) = (DI) +1
That is: Inc si
Inc di
When Df=1, (si) = (si)-1
(di) = (DI)-1
namely: Dec si
Dec di

Format:MOVSW; MOV string word
Function: 1) ((es) *16+ (di)) = ((ds) *16+ (SI))
ie: mov es:[di],word ptr ds:[si]
2) when df=0, (si) = (si) +2
(di) = (DI) +2
That is: Add si,2
Add di,2
When Df=1, (si) = (si)-2
(di) = (DI)-2
That is: Sub Si
Sub di
General MOVSB/MOVSW in conjunction with Rep; rep-repeat
Format:Rep MOVSB
namely: S:MOVSB
loop S; The role of rep is to repeat the string transfer based on CX values

Instructions for setting DF:
CLD; Place DF 0, string Transfer--offset address increment direction clear DF
STD; Place DF 1, string Transfer--offset address descending direction set DF

Assume Cs:code,ds:datadata segment  db ' Welcome to masm! '            ; Copy this string to the same segment address, offset address 16 memory location  db (0)                    data endscode segment  Start:mov ax,data         mov ds,ax         mov es, AX mov si,0 mov di,16 mov cx,8 CLD rep MOVSW  mov ax,4c00h int 21hcode endsend start

PUSHF and Popf:

PUSHF function--the value of the tag register is pressed to stack;

Popf function--out of the stack, the value is fed into the tag register.

Note: This article refers to the network and "Assembly language" (Wang Shuang, second edition)

Assembly Language Tag register mark bit _nv up EI NG NZ AC PE CY

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.