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.

Slides:



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

Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU
Computer Organization & Assembly Language
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
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.
11.1/36 Repeat: From Bits and Pieces Till Strings.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Types of Registers (8086 Microprocessor Based)
LAB Flag Bits and Register
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Arithmetic Flags and Instructions
ECE291 Computer Engineering II Lecture 4 Josh Potts University of Illinois at Urbana- Champaign.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
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.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
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.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
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.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
ECE291 Computer Engineering II Lecture 4 Josh Potts University of Illinois at Urbana- Champaign.
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
Lecture 4: Digital Systems & Binary Numbers (4)
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
16.317: Microprocessor System Design I
8086 Microprocessor.
Microprocessor Systems Design I
ICS312 SET 7 Flags.
Chapter 3 Bit Operations
Microprocessor Systems Design I
The FLAGS Register An x bit means an unidentified value 9/12/2018
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
More on logical instruction and
Assembly Language Programming Part 2
Introduction to Assembly Language
Lecture 4 ( Assembly Language).
Flags Register & Jump Instruction
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
Shift & Rotate Instructions)
University of Gujrat Department of Computer Science
Shift & Rotate Instructions)
CNET 315 Microprocessor & Assembly Language
Chapter 5 Arithmetic and Logic Instructions
Computer Architecture and System Programming Laboratory
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Part I Data Representation and 8086 Microprocessors
CS-401 Computer Architecture & Assembly Language Programming
Ch. 5 – Intel 8086 – study details from Yu & Marut
Two’s Complement & Binary Arithmetic
Part IV The FLAGS Register
Presentation transcript:

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 3.Status reg / FLAGS reg

3. Status Reg./FLAGS reg. To indicate the status of the mP. 1 flag == 1 bit Y/N  9 active bits – out of ?? Bits? Q: Types of flags? Some names? a.Control flags – interrupt flag, trap flag, direction flag b.Status flags – Zero flag, Carry flag, sign flag, parity, auxiliary flag, overflow flag

Status flags Processor uses the status flags to reflect the result of an operation. E.g., SUBAX, AX  Zero flag becomes 1  It indicates that a zero result was produced

Carry flag - CF CF = 1  if there is a carry out from the MSB on addition;  or, there is a borrow into the MSB on subtraction; Else CF = 0 CF changes with SHIFT (SHL – shift left; SAL – shift arithmetic left; SHR – shift right; SAR – shift arithmetic right) & ROTATE (ROL – rotate left; ROR – rotate right) instructions  Read – chapter 7

Parity flag - PF PF = 1  If the low byte of a result has an even number of one bits [even parity] PF = 0  If the low byte has odd parity Q.: If after ADD – the result is FFFEh – then the low byte [FE] contains 7 one bits [FE = ], PF = ? Ans.: PF = 1  Nooooooo…  PF = 0

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 is used in BCD operations [see ch. 18] BCD – Binary-Coded Decimal [BCD uses 4 bits to code each decimal digit, from 0000 to Combination of 1010 to 1111 are illegal in BCD.

Zero flag - ZF ZF = 1  For a zero result ZF = 0  For a nonzero result

Sign flag - SF SF = 1  If the MSB of a result is 1  It means the result is negative if you are giving a signed interpretation SF = 0  If the MSB is 0

Overflow flag - OF OF = 1  If signed overflow occurred 16 bits: singed: range: ~ unsinged: 0 ~ bits:signed: -128 ~ 127 unsigned: 0 ~ 255

Unsigned overflow What is overflow? exa of unsigned overflow but not singed overflow e.g.,  AX = FFFFh  16 bits  BX = 0001h  16 bits  ADDAX, BX Result:  17 bits, not 16 bits So, AX = = 0000h So, unsigned overflow occurred.

If unsigned interpretation – then Answer  10000h =  but 17 bits In 16 bits  AX = 0000h is the result! – WRONG! An unsigned overflow occurred. BUT the answer is CORRECT for a signed number – FFFFh = h =1 FFFFh h = = 0  so, singed overflow did not occur.

Signed OF, not unsigned OF AX = 7FFFh BX = 7FFFh ADDAX,BX So, AX = = FFFEh =  This is out of range for signed nos.  So, singed OF occurs  But for unsinged no., it is ok.

Q. Questions are then – 1.How does the CPU indicate overflow? 2.How does it know that overflow occurred?

1. How does the CPU indicate overflow? CPU sets OF = 1 for signed OF CPU sets CF = 1 for unsigned OF It is the Programmer who interpret the results. If a signed interpretation is being given, then only OF is of interest & CF can be ignored. If unsigned?  CF is important, but not OF.

2. How CPU knows that overflow occurred? Many instructions can cause overflow, e.g., ADD, SUB

For unsigned overflow ADD: unsigned overflow occurs when there is a carry out of the MSB. [i.e., if result is larger than the capacity]. SUB: … when there is a borrow into the MSB. [i.e., the correct answer is smaller than 0]

For signed overflow ADD: On addition of nos. with the same sign, signed overflow occurs when the sum has a different sign. E.g., 7fffh + 7fffh = fffeh = 1111……0  It is a negative result.

For signed overflow… SUB: Subtraction of 2 nos. of different signs – means adding nos. of same sign. E.g., A – (-B) = A + B. -A – (+B) = -A + -B Signed overflow occurs if the result has a different sign than expected.  exa But, if ADD of nos. of different signs – overflow is impossible. A + (-B) = A – B  Result is smaller than A or B. No chance for overflow. Likewise, SUB of nos. of same signs  no overflow

Exa. 5.3 AX = 8000h [neg. no.]BX=0001h SUB AX,BX 8000h – 0001h = 7fffh = CF = 0  as a smaller unsigned no. is being subtracted from a larger one. OF?  OF: in a singed sense, subtracting from a positive no. (BX) from a negative no. (AX)  means adding 2 negatives [-A – B = -A + (-B)]. Result is Positive (wrong sign), OF = 1 Convert these into decimal and see.

Actually, the processor uses this method to set the OF: If the carries into and out of the MSB doesn’t match – i.e., there is a carry into the MSB but no carry out, or, If there is a carry out but no carry in – then signed overflow is occurred, & OF is set to see exa. 52.

Exa. 5.2: AL = 80hBL = 80h ADD AL,BL 80h + 80h = 1 00h So, AL = 00h CF = 1: as there is a carry out of MSB OF = 1: as both nos. are negative [80h= ], but the result = 00h (as binary addition, there is no carry into the MSB, but there is a carry out)

How instructions affect the flags? Usually, each time a mP executes an instruction – the flags are altered to reflect the result JMP [jump] instr. depend on the flags settings MOV/XCHGnone [no change] ADD/SUBall INC/DECall except CF

Q.: ADDAX, BX AX = FFFFh BX = FFFFh So, after ADD, AX = 1 FFFEh So inside …