1 / 7

CHAPTER 3

CHAPTER 3. LAB Flag Bits and Register. 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 .

camden
Download Presentation

CHAPTER 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 • 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 = 1111 1111 1111 1110. 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)

More Related