1 / 15

Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization & Assembly Language Lecture 14 Flags Register. Outline. Study from Lecture Notes Introduction The FLAGS Register Overflow

aleda
Download Presentation

Riyadh Philanthropic Society For Science Prince Sultan College For Woman

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. Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization & Assembly Language Lecture 14 Flags Register

  2. Outline • Study from Lecture Notes • Introduction • The FLAGS Register • Overflow • How an instruction affects the flags Flags Register

  3. Introduction • One important feature that distinguishes a computer from other machines is the computer’s ability to make decisions. • Decision are made based on the current state of the processor. • In the 8086 processor, the processor state is implemented as nine 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. Flags Register

  4. Flags Register - Types • Two kinds of flags: • Status flags: reflect the result of an instruction executed by the processor (ex. When a subtraction results in a 0, the ZF “Zero Flag” is set to 1, a subsequent instruction can examine the ZF and branch to some code that handles a zero result) • Control Flag: enable or disable certain operations of the processor (ex. If the IF “Interrupt Flag” is set to 0, inputs from the keyboard are ignored by the processor). Flags Register

  5. Flags Register – Bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OF DF IF TF SF ZF AF PF CF Flags Register • Status Flags • Carry Flag (CF) • Parity Flag (PF) • Auxiliary carry Flag (AF) • Zero Flag (ZF) • Sign Flag (SF) • Overflow Flag (OF) • Control Flags • Trap Flag (TF) • Interrupt Flag (IF) • Direction Flag (DF)

  6. Flags Register – Status Flags (1) • Carry Flag (CF): • CF = 1 if there is a carry out from the msb on addition. • CF = 1 if there is a borrow into the msb on subtraction. • CF = 0 otherwise. • CF is also affected by shift and rotate instructions. • Parity Flag (PF): • PF = 1 if the low byte of a result has an even number of one bits • PF = 0 if the low byte has odd parity (ex. if a result is FFFE PF = 0). Flags Register

  7. Flags Register – Status Flags (2) • Auxiliary carry Flag (AF): • AF = 1 if there is a carry out from bit 3 on addition. • AF = 1 if there is a borrow into bit 3 on subtraction. • AF = 0 otherwise. • AF is used in BCD operations. • Zero Flag (ZF): • ZF = 1 for a zero result. • ZF = 0 for nonzero result. Flags Register

  8. Flags Register – Status Flags (3) • Sign Flag (SF): • SF = 1 if the msb of a result is 1. (i.e. Negative if signed interpretation is used). • SF = 0 if the msb is 0. • Overflow Flag (OF): • OF = 1 if signed overflow occurred. • OF = 0 otherwise. Flags Register

  9. Processor & Overflow Determination • Signed Overflow • On addition of numbers with the same sign, signed overflow occurs when the sum has a different sign. • Subtraction of numbers with different signs is like adding numbers of the same sign (ex. A - (-B) = A + B). Signed overflow occurs if the result has a different sign than expected. • In addition of numbers with different signs, overflow is impossible. • Subtraction of numbers with the same sign cannot give overflow. Flags Register

  10. How Instructions Affect The Flags Instruction Affects flags MOV/XCHG none ADD/SUB all INC/DEC all except CF NEG all (CF = 1 unless result is 0, OF = 1 if word operand is 8000h or byte operand is 80h) • In general, each time the processor executes an instruction, the flags are altered to reflect the result. • However, some instructions don’t affect any of the flags, affects only some of them, or may leave them undefined. Flags Register

  11. How Instructions Affect The Flags EX. • Example: ADD AX, BX where AX contains FFFFh, BX contains FFFFh FFFFh +FFFFh 1FFFEh = 1111 1111 1111 1110b • SF = 1 because the msb is 1. • PF = 0 because there are 7 (odd number) of 1 bits in the low byte. • ZF = 0 because the result is nonzero. • CF = 1 because there is a carry out of the msb on addition. • OF = 0 because the sign of the stored result is the same as that of the numbers being added. Flags Register

  12. How Instructions Affect The Flags EX.(2) • Example: ADD AL, BL where AL contains 80h, BL contains 80h 80h +80h 100h • SF = 0 because the msb is 0. • PF = 1 because all the bits in the result are zero. • ZF = 1 because the result is 0. • CF = 1 because there is a carry out of the msb on addition. • OF = 1 because the numbers being added are both negative, but the result is 0. Flags Register

  13. How Instructions Affect The Flags EX.(3) • Example: SUB AX, BX where AX contains 8000h, BX contains 0001h 8000h - 0001h 7FFFh = 0111 1111 1111 1111b • SF = 0 because the msb is 0. • PF = 1 because there are 8 (even number) one bits in the low byte. • ZF = 0 because the result is nonzero. • CF = 0 because a smaller unsigned number is being subtracted from a larger one • OF = 1 because a positive number is being subtracted from a negative one (like adding two negatives), and the result is positive. Flags Register

  14. How Instructions Affect The Flags EX.(4) • Example: SUB AX, -5 None of the flags are affected by MOV Flags Register

  15. How Instructions Affect the Flags Example: MOV AX, -5 None of the flags are affected by MOV. Flags Register

More Related