Lecture 4 ( Assembly Language).

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

How Instruction Affect the Flags
Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU
Computer Organization & Assembly Language
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Ch. 5 from Yu & Marut. Registers 14(16-bit) registers: 1.Data reg. – to hold data for an op. 2.Address reg – to hold addr of an instruction or data.
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
An Introduction to 8086 Microprocessor.
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Electrical Engineering Department Engineering College Prince Sattam bin Abdul Aziz University Text Book: - Triebel and Singh, "The 8088 and 8086 Microprocessors",
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
1 Fundamental of Computer Suthida Chaichomchuen : SCC
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR1 Addressing Mode.
Types of Registers (8086 Microprocessor Based)
LAB Flag Bits and Register
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Arithmetic Flags and Instructions
(Flow Control Instructions)
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
Introduction to Microprocessors Chapter 3. Programming Model (8086)  Shows the various internal registers that are accessible to the programmer.
Introduction to Computer Organization and Assembly Language
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Intel 8086 MICROPROCESSOR ARCHITECTURE
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
CS2422 Assembly Language and System Programming 0 Week 9 Data Transfers, Addressing, and Arithmetic.
UNIT Architecture M.Brindha AP/EIE
Introduction to 8086 Microprocessor
8086 Microprocessor.
ICS312 SET 7 Flags.
Intel 8086 MICROPROCESSOR Architecture.
The FLAGS Register An x bit means an unidentified value 9/12/2018
Assembly Language for Intel-Based Computers, 5th Edition
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Multiplication and Division Instructions
Microprocessor and Assembly Language
More on logical instruction and
Intel 8088 (8086) Microprocessor Structure
..
CS-401 Assembly Language Programming
Introduction to Assembly Language
Flags Register & Jump Instruction
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Data Transfers, Addressing, and Arithmetic
Microprocessor & Assembly Language
Intel 8088 (8086) Microprocessor Structure
CS 301 Fall 2002 Computer Organization
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
Shift & Rotate Instructions)
University of Gujrat Department of Computer Science
Shift & Rotate Instructions)
Flags Carry flag Overflow Parity flag Direction Interrupt enable
Computer Architecture and System Programming Laboratory
Microprocessor and Assembly Language
Multiplication and Division Instructions
Multiplication and Division Instructions
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Architecture and Assembly Language
Ch. 5 – Intel 8086 – study details from Yu & Marut
Two’s Complement & Binary Arithmetic
Part IV The FLAGS Register
Presentation transcript:

Lecture 4 ( Assembly Language)

Lecture Outline Introduction The FLAGS Register Overflow How instruction affect the flags

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.

The FLAGS Register Two kinds of flags: Status flags: reflect the result of an instruction executed by the processor (ex. ZF ,PF ,SF ,OF) 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).

The FLAGS Register 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Status Flags OF DF IF TF SF ZF AF PF CF 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)

The FLAGS Register - Status Flags 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).

The FLAGS Register - Status Flags 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.

The FLAGS Register - Status Flags 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.

Overflow The phenomenon of overflow is associated with the fact that the range of numbers that can be represented in a computer is limited. If the result of an operation falls outside the range, overflow occurs and the truncated result that is saved will be incorrect.

How the Processor Determines that Overflow Occurred? 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.

How Instructions Affect the Flags 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. Instruction Affects flags MOV/XCHG none ADD/SUB all INC/DEC all except CF

How Instructions Affect the Flags 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.

How Instructions Affect the Flags 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.

How Instructions Affect the Flags 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.

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