Introduction to Computer Engineering by Richard E. Haskell Addition and Subtraction Instructions Module M16.3 Section 10.4.

Slides:



Advertisements
Similar presentations
Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.
Advertisements

Introduction to Computer Engineering by Richard E. Haskell Multiplication and Division Instructions Module M16.4 Section 10.4.
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
EE1A2 Microprocessor Systems & Digital Logic Part I Digital Electronic System Design Dr. T. Collins.
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
HEXADECIMAL NUMBERS Code
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Addition of two binary numbers = = = = 39.
Number Systems Discussion D4.1 Appendix C. Number Systems Counting in Binary Positional Notation Hexadecimal Numbers Negative Numbers.
King Fahd University of Petroleum and Minerals
Binary Subtraction Section 3-9 Mano & Kime. Binary Subtraction Review from CSE 171 Two’s Complement Negative Numbers Binary Adder-Subtractors 4-bit Adder/Subtractor.
Introduction to Computer Engineering by Richard E. Haskell Branching Instructions Module M17.2 Section 11.1.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Fixed-Point Arithmetics: Part I
Adders Lecture L7.1 Section 6.2 Section 10.4 (pp )
Shift and Rotate Instructions
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Introduction to Computer Engineering by Richard E. Haskell Logical Instructions Module M16.6 Section 10.5.
Negative Numbers Module M3.3 Section 2.4. Negative Numbers Subtract by adding ’s complement Ignore carry.
IT Systems Number Operations EN230-1 Justin Champion C208 –
Digital Computers and Information Chapter 1 Mano and Kime.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
©2008 The McGraw-Hill Companies, Inc. All rights reserved. Digital Electronics Principles & Applications Seventh Edition Chapter 10 Arithmetic Circuits.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
The 8051 Microcontroller and Embedded Systems
Chapter 6 Digital Arithmetic: Operations and Circuits ECE 221 Intro
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
ASCII and BCD Arithmetic Chapter 11 S. Dandamudi.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Lecture 4 ( Assembly Language).
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
Arithmetic Flags and Instructions
ARITHMETIC MICRO OPERATIONS
Combinational Circuits
Addition and Substraction
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
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.
Introduction to Microprocessors Chapter 3. Programming Model (8086)  Shows the various internal registers that are accessible to the programmer.
Two’s and one’s complement arithmetic CLOCK ARITHMETIC.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Chapter 6. Digital Arithmetic: Operations and Circuits
Digital Arithmetic Wen-Hung Liao, Ph.D..
ICS312 SET 7 Flags.
The FLAGS Register An x bit means an unidentified value 9/12/2018
Assembly Language for Intel-Based Computers, 5th Edition
X86’s instruction sets.
ELL100: INTRODUCTION TO ELECTRICAL ENGG.
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
CPS120: Introduction to Computer Science
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
COMS 361 Computer Organization
Part IV The FLAGS Register
Presentation transcript:

Introduction to Computer Engineering by Richard E. Haskell Addition and Subtraction Instructions Module M16.3 Section 10.4

Introduction to Computer Engineering by Richard E. Haskell Binary Addition Can add immediate data to a register or memory. Can add data from a register to a register. Can add data from a register to memory. Can add data from memory to a register. Can NOT add data directly from one memory location to another.

Introduction to Computer Engineering by Richard E. Haskell

Recall Full Adder Truth Table C i A i B i S i C i A B C Final carry = 0

Introduction to Computer Engineering by Richard E. Haskell Binary Addition E Dec Hex Binary

Introduction to Computer Engineering by Richard E. Haskell Add 35H and 19H 0000 B0 35 MOV AL,35H ADD AL,19H sum = 4EH in AL

Introduction to Computer Engineering by Richard E. Haskell Carry and Overflow C = 0 O = E Dec Hex Binary Note no carry from bit 6 to bit 7 and no carry from bit 7 to C.

Introduction to Computer Engineering by Richard E. Haskell Carry and Overflow C = 0 O = B 90 Dec Hex Binary Thinking SIGNED we added two positive numbers and got a negative result. This can’t be correct! Therefore, the OVERFLOW bit, O, is set to 1. Correct answer (144) is outside the range -128 to Note carry from bit 6 to bit 7 but no carry from bit 7 to C.

Introduction to Computer Engineering by Richard E. Haskell Carry and Overflow C = 1 O = D3 108 Dec Hex Binary Thinking SIGNED we added a positive number to a negative number and got the correct positive answer. Therefore, the OVERFLOW bit, O, is cleared to 0. Correct answer (8) is inside the range -128 to Ignore carry Note carry from bit 6 to bit 7 and carry from bit 7 to C.

Introduction to Computer Engineering by Richard E. Haskell Carry and Overflow C = 1 O = E +D3 171 Dec Hex Binary Thinking SIGNED we added two negative numbers and got a positive answer. This must be wrong! Therefore, the OVERFLOW bit, O, is set to 1. Correct answer (-143) is outside the range -128 to Ignore carry Note no carry from bit 6 to bit 7 but there is a carry from bit 7 to C.

Introduction to Computer Engineering by Richard E. Haskell Carry and Overflow Summary 0000 B0 35 MOV AL,35H ADD AL,19H sum = 4EH in AL, C=0, O= B0 35 MOV AL,35H B ADD AL,5BH sum = 90H in AL, C=0, O= B0 35 MOV AL,35H 000A 04 D3 ADD AL,D3H sum = 08H in AL, C=1, O=0 000C B0 9E MOV AL,9EH 000E 04 D3 ADD AL,D3H sum = 71H in AL, C=1, O=1

Introduction to Computer Engineering by Richard E. Haskell Overflow Note that the overflow bit was set whenever we had a carry from bit 6 to bit 7, but no carry from bit 7 to C. It was also set when we had a carry from bit 7 to C, but no carry from bit 6 to bit 7. Upshot: The overflow bit is the EXCLUSIVE-OR of a carry from bit 6 to bit 7 and a carry from bit 7 to C.

Introduction to Computer Engineering by Richard E. Haskell Binary Subtraction Can subtract immediate data from a register or memory. Can subtract a register from a register. Can subtract a register from memory. Can subtract memory from a register. Can NOT subtract data in one memory location from that in another memory location.

Introduction to Computer Engineering by Richard E. Haskell

Recall Full Subtractor Truth Table C i A i B i D i C i A B C Final borrow = E Hex

Introduction to Computer Engineering by Richard E. Haskell Binary Subtraction B5 - 6F 46 Dec Hex Binary Final borrow = 0

Introduction to Computer Engineering by Richard E. Haskell Subtract 6FH from B5H 0000 B0 B5 MOV AL,B5H C 6F SUB AL,6FH difference = 46H in AL

Introduction to Computer Engineering by Richard E. Haskell Binary Subtraction C = B5 - 6F 46 Dec Hex Binary This is the correct answer if we consider B5H to be UNSIGNED and equal to 181. But suppose you were thinking of B5H = as the 2’s complement negative number = 4BH or -75.

Introduction to Computer Engineering by Richard E. Haskell Binary Subtraction C = 0 O = B5 - 6F 46 Dec Hex Binary Thinking SIGNED we subtracted a positive number from a negative number and got a positive answer. This must be wrong! Therefore, the OVERFLOW bit, O, is set to 1. Correct answer (-186) is outside the range -128 to +127.

Introduction to Computer Engineering by Richard E. Haskell Binary Subtraction Borrow = !Carry C = B5 - 6F 46 Dec Hex Binary Take the two’s complement of 6F and add. 6FH = = 91H B Ignore carry Note no carry from bit 6 to bit 7 but there is a carry from bit 7 to C. Therefore, overflow, O = 1.

Introduction to Computer Engineering by Richard E. Haskell 16-Bit Addition 37FAH +82C4H BABEH 0000 B8 FA 37 MOV AX,37FAH C4 82 ADD AX,82C4H sum = BABEH in AX

Introduction to Computer Engineering by Richard E. Haskell 16-Bit Subtraction A1C9H -8315H 1EB4H 0000 B8 C9 A1 MOV AX,A1C9H D SUB AX,8315H difference = 1EB4H in AX

Introduction to Computer Engineering by Richard E. Haskell Sign extending bytes to words 5 = = = FBH 16 bits -5 = = FFFBH To add an 8-bit signed number to a 16-bit signed number the 8-bit number must be sign extended: If bit 7 is 1, make bits one. If bit 7 is 0, make bits zero.

Introduction to Computer Engineering by Richard E. Haskell CBW (Convert Byte to Word) The 8086 instruction CBW extends the sign bit of AL into AH. Similar words for other microprocessors: 68000: EXT (sign EXTend) 6809: SEX (Sign EXtend)

Introduction to Computer Engineering by Richard E. Haskell Add 8-bits to 16-bits (signed) FFFBH +123AH 1235H Sign extend FBH +123AH 0000 B0 FB MOV AL,0FBH ;AL = CBW ;AX = A 12 ADD AX,123AH AX = sum