Download presentation

1
**LAB Flag Bits and Register**

CHAPTER 3 LAB Flag Bits and Register

2
Overview The circuits in the CPU can perform simple decision making based on the current state of the processor. For the 8086 processor, the processor state is implemented as 9 individual bits called flags. Each decision made by the 8086 is based on the values of these flags. The flags are placed in the FLAGS register and they are classified as either status flags or control flags. The status flags reflect the result of a computation.

3
**FLAGS Register Figure above shows the FLAGS register**

Figure above shows the FLAGS register The status flags are located in bits 0, 2, 4, 6, 7 and 11 and the control flags are located in bits 8, 9 and 10. The other bits have no significance. The STATUS flags – the processor uses the status flags to reflect the result of an operation: CARRY FLAGS (CF) : CF = 1, if there is a carry out form MSB on addition, or there is borrow into MSB on subtraction. Otherwise, it is 0. PARITY FLAGS (PF) : PF = 1, if the low byte of a result has even number of one bits (even parity). It is 0 if the low byte has odd parity. Eg. Result of addition is FFFEh, then the low byte contains 7 one bits, so PF = 0. OF DF IF TF SF ZF AF PF CF

4
Auxiliary Carry Flag (AF) : AF = 1 if there is a carry out from bit 3 on addition, or a borrow into bit 3 on subtraction. AF used in BCD operations only Zero Flag (ZF) : ZF = 1 for a zero result, and ZF = 0 for nonzero result. Sign Flag (SF) : SF = 1 if the msb of a result is 1; it means the result is negative (signed interpretation). SF = 0 if the msb in 0. Overflow flag (OF) : OF = 1 if signed overflow occurred, otherwise it is 0.

5
**How instruction Affect the Flags**

In general, each time the processor executes an instruction, the flags are altered to reflect the result. Let’s return to the seven basic instructions, they affect the flags as follows: Instruction Affect Flags MOV/XCHG none ADD/SUB all INC/DEC all excepts CF NEG all (CF = 1 unless result is 0 OF = 1 if word operand is 8000h or byte operand is 80h)

6
**Example 1 ADD AX, BX where AX contain FFFFh and BX contains FFFFh**

Sol: FFFFh + FFFFh 1 FFFEh The result stored in AX is FFFEh = SF = 1 because the msb is 1 PF = 0 because the are 7 (odd number) of 1 bits in the low byte of the result ZF = 0 : result is nonzero CF = 1: carry out of the msb on addition OF = 0: sign of the stored result is the same as that of the numbers being added.

7
**Exercise ADD AL, BL (AL = 80h, BL = 80h)**

SUB AX, BX (AX = 8000h, BX = 0001h) INC AL (AL = FFh) MOV AX, -5 NEG AX (AX = 8000h)

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google