COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers

Slides:



Advertisements
Similar presentations
Cosc 2150: Computer Organization Chapter 9, Part 2 Integer multiplication and division.
Advertisements

Binary Arithmetic Binary addition Binary subtraction
THE ARITHMETIC-LOGIC UNIT. BINARY HALF-ADDER BINARY HALF-ADDER condt Half adder InputOutput XYSC
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
CMP 101 Fundamentals of Computer and programming in C Rohit Khokher.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Computer Arithmetic.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Multiplication of signed-operands
Figure 1.1 Block diagram of a digital computer. Functional Units.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
Integer Operations Computer Organization and Assembly Language: Module 5.
C OMPUTER A RITHMETIC. I NTRODUCTION A processor has an separate unit that is known as ALU that executes arithmetic operations. Negative numbers may be.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
= 91 sum operation augend addend NOTE: Sometimes both the augend and addend are called addends. Sometimes the sum is called the total. Addition.
Computer Arithmetic. Integer Representation Sign-magnitude representation ’s complement representation magnitudes
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Computer System Design Lecture 3
More Binary Arithmetic - Multiplication
COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers
Multiplication and Division basics
Array multiplier TU/e Processor Design 5Z032.
Unit -2 ARITHMETIC.
Morgan Kaufmann Publishers
Lecture 16 Arithmetic Circuits
William Stallings Computer Organization and Architecture 7th Edition
Data Representation and Arithmetic Algorithms
Topic 3c Integer Multiply and Divide
Computer Organization and Design
Multiprocessor & Multicomputer
ECEG-3202 Computer Architecture and Organization
Data Representation and Arithmetic Algorithms
Computer Architecture
Chapter 8 Computer Arithmetic
CHAPTER 18 Circuits for Arithmetic Operations
Arithmetic Logic Unit A.R. Hurson Electrical and Computer Engineering Missouri University of Science & Technology A.R. Hurson.
Presentation transcript:

COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers Multiplication and Division Floating-Point Arithmetic Operations Decimal Arithmetic Unit Decimal Arithmetic Operations

SIGNED MAGNITUDEADDITION AND SUBTRACTION Addition: A + B ; A: Augend; B: Addend Subtraction: A - B: A: Minuend; B: Subtrahend (+A) + (+B) (+A) + (- B) (- A) + (+B) (- A) + (- B) (+A) - (+B) (+A) - (- B) (- A) - (+B) (- A) - (- B) +(A + B) - (A + B) +(A - B) - (A - B) - (B - A) +(B - A) Operation Magnitude When A>B When A<B When A=B Add Subtract Magnitude Hardware Implementation Bs B Register AVF Complementer M(Mode Control) Output Carry Input Carry E Parallel Adder S As A Register Load Sum

SIGNED 2’S COMPLEMENT ADDITION AND SUBTRACTION Hardware B Register Complementer and Parallel Adder V Overflow AC Algorithm Subtract Add Minuend in AC Subtrahend in B Augend in AC Addend in B AC  AC + B’+ 1 V  overflow AC  AC + B V  overflow END END

MULTIPLICATION  2i * Ai ) Multiplication: B * A; B: Multiplicand; A: Multiplier; P: Partial Product Multiplication of Unsigned Positive Numbers A = An-1An-2 ... A0 B = Bn-1Bn-2 ... B0 P = B * A n-1 = B * (  2i * Ai ) i=0 = An-1 * (B2n-1) + An-2 * (B2n-2) + ... + A0 * (B20) B shifted left B shifted left B shifted left n-1 bits n-2 bits 0 bits = A Or B shifted (n-1) bits to the left P = An-1*(B2n-1 * 20) + An-2*(B2n-1 * 2-1) + ... + A0*(B2n-1 * 2-(n-1)) B2n-1 B2n-1 shifted right B2n-1 shifted right 1 bit (n-1) bits

EXAMPLE Multiplier in Q 0 00000 10011 101 Q0 = 1; add B 10111 Multiplication EXAMPLE Multiplicand B=10111 E A Q SC Multiplier in Q Q0 = 1; add B First partial product Shift right EAQ Second Partial Product Q0 = 0; shift right EAQ Fifth partial product Final Product in AQ = 0110110101 0 00000 10011 101 10111 0 10111 0 01011 11001 100 1 00010 0 10001 01100 011 0 01000 10110 010 0 00100 01011 001 0 11011 0 01101 10101 000

SIGNED MAGNITUDE MULTIPLICATION Bs Hardware B Register Sequence Counter Complementer and Parallel Adder As Qn Qs 0 E AC Q Register EAQ B <- Multiplicand B Q <- MultiplierA Algorithm As,Qs <- Qs  Bs A <- 0, E <- 0 SC <- n-1 = 0 =1 Q0 EA <- A + B shr EAQ SC <- SC+1 = 0 END Product in AQ =0 SC

BOOTH MULTIPLICATION ALGORITHM FOR SIGNED 2’S COMPLEMENT Multiplier Strings of 0’s: No addition; Simply shifts Strings of 1’s: String of 1’s from mp to mq: 2p+1 - 2q Example 001110 (14) -> p = 3, q = 1 001110 = 23+1 - 21 M * 14 = M24 - M21 Algorithm [1] Subtract multiplicand for the first least significant 1 in a string of 1’s in the multiplier [2] Add multiplicand for the first 0 after the string of 1’s in the multiplier [3] Partial Product does not change when the multiplier bit is identical to the previous bit 110010 = -24 + 22 - 21 = -16 + 4 - 2 = -14 subtract subtract 24 21 Add 22

BOOTH ALGORITHM FOR SIGNED 2’S COMPLEMENT Multiplication BOOTH ALGORITHM FOR SIGNED 2’S COMPLEMENT B <- Multiplicand B Q <- Multiplier A AC <- 0 Q-1 <- 0 SC <- n 10 01 Q0Q-1 ? Q-1 : shifted out bit on shr of Q 11 00 AC<-AC+B’+1 AC <- AC + B ashr(AC&Q) SC <- SC + 1  0 SC ? =0 END

EXAMPLE OF BOOTH MULTIPLIER Multiplication EXAMPLE OF BOOTH MULTIPLIER B = 10111 Q0Q-1 B’+1=01001 AC Q Q-1 SC 10 11 01 00 Initial Subtract B ashr Add B 00000 10011 0 101 01001 00100 11001 1 100 00010 01100 1 011 10111 11001 11100 10110 0 010 11110 01011 0 001 00111 00011 10101 1 000

ARRAY MULTIPLIER A = a1a0: Multiplier B = b1b0: Multiplicand b1 b0 Multiplication ARRAY MULTIPLIER A = a1a0: Multiplier B = b1b0: Multiplicand C = B * A = c3c2c1c0 b1 b0 a1 a0 a0b1 a0b0 a1b1 a1b0 c3 c2 c1 c0 b1 b0 a0 b1 b0 a1 HA HA C S C S c3 c2 c1 c0

ARRAY MULTIPLIER 4-BIT X 3-BIT Multiplication ARRAY MULTIPLIER 4-BIT X 3-BIT a0 a1 b3 b2 b1 b0 b3 b2 b1 b0 Addend Augend 4-bit Adder Sum and Carry Outputs a2 b3 b2 b1 b0 Addend Augend 4-bit Adder Sum and Carry Outputs c6 c5 c4 c3 c2 c1 c0

Division DIVISION A / B = Q + R A: Dividend; B: Divisor; Q: Quotient; R: Remainder Divisor B = 10001, B’+ 1 = 01111 E A Q SC Dividend: shl EAQ add B’+1 E=1 Set Q0=1 Add B’+1 E=0; Q0=0 add B restore remainder neglect E remainder in A quotient in Q 01110 00000 5 0 11100 00000 01111 1 01011 1 01011 00001 4 0 10110 00010 1 00101 1 00101 00011 3 0 01010 00110 0 11001 00110 10001 1 01010 2 0 10100 01100 1 00011 1 00011 01101 1 0 00110 11010 0 10101 11010 1 00110 11010 0 00110 11010

FLOWCHART OF DIVIDE OPERATION Division FLOWCHART OF DIVIDE OPERATION Dividend in AQ Divisor in B Qs As  Bs SC<- n - 1 shl EAQ E EA  A + B’+1 EA  A+B’+1 A  A+B’+1 1 E 1 A B A<B E 0(A<B) A B Q0  1 EA  A+B EA  A+B DVF  1 DVF  0 EA  A+B SC  SC-1  0 SC END (Divide overflow) END (Quotient in Q Remainder in R)

FLOATING POINT ARITHMETIC OPERATIONS F = m x re where m: Mantissa r: Radix e: Exponent Registers for Floating Point Arithmetic Bs B b BR Parallel Adder and Comparator E Parallel Adder As A1 A a AC Qs Q q QR

FLOATING POINT ADD AND AUBTRACT Floating Point Arithmetic FLOATING POINT ADD AND AUBTRACT =0  0  0 BR AC CHECK FOR =0 a<b a>b a:b Align Mantissa AC  BR shr A a  a+1 shr B b  b+1 add op sub sub add As  A’s op 1 1 As  Bs As  Bs + or - of mantissa EA<-A+B’+1 EA  A+B A  A’+1 As  A’s E 1  0 =0 A Normalization A1 AC  0 E shl A a  a+1 shr A A1  E a  a+1 END

FLOATING POINT MULTIPLICATION Floating Point Arithmetic FLOATING POINT MULTIPLICATION BR  Multiplicand QR  Multiplier =0 BR  0 =0 QR  0 AC  0 a  q a  a + b a  a - bias Multiply mantissa (finxed point multiplication) shl AQ a  a - 1 A1 1 END (Product is in AC)

FLOATING POINT DIVISION Floating Point Arithmetic FLOATING POINT DIVISION BR  Divisor AC  Dividend =0 BR  0 =0 AC  0 QR  0 Qs  As + Bs Q  0 SC  n-1 divide by 0 EA  A+B’+1 1 E A>=B A<B A  A+B shr A a  a+1 A  A+B a  a+b’+1 a  a+bias q  a Divide Magnitude of mantissa as in fixed point numbers

BCD ADD BCD digit < 10 BCD digit + BCD digit + carry =< 19 BCD Arithmetic BCD ADD BCD digit < 10 BCD digit + BCD digit + carry =< 19 Binary Sum BCD Sum K Z8 Z4 Z2 Z1 C S8 S4 S2 S1 Decimal 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 2 0 0 0 1 1 0 0 0 1 1 3 0 0 1 0 0 0 0 1 0 0 4 0 0 1 0 1 0 0 1 0 1 5 0 0 1 1 0 0 0 1 1 0 6 0 0 1 1 1 0 0 1 1 1 7 0 1 0 0 0 0 1 0 0 0 8 0 1 0 0 1 0 1 0 0 1 9 0 1 0 1 0 1 0 0 0 0 10 0 1 0 1 1 1 0 0 0 1 11 0 1 1 0 0 1 0 0 1 0 12 0 1 1 0 1 1 0 0 1 1 13 0 1 1 1 0 1 0 1 0 0 14 0 1 1 1 1 1 0 1 0 1 15 1 0 0 0 0 1 0 1 1 0 16 1 0 0 0 1 1 0 1 1 1 17 1 0 0 1 0 1 1 0 0 0 18 1 0 0 1 1 1 1 0 0 1 19

BCD ADDER If we can convert Binary Sums to BCD Sum , BCD Arithmetic BCD ADDER If we can convert Binary Sums to BCD Sum , we can use a binary adder to add two BCD numbers SUM =< 9 BCD Sum = Binary Sum BCD Carry = Binary Carry 19 >= SUM > 9 BCD Sum = Binary Sum + 0110 BCD Carry = Carry(Binary Sum + 0110) 4-bit Binary Add 1 K Take next higher digit Z8 1 1 Z4 done ? 1 END Z2 BCD Sum  Sum + 0110 BCD C  Carry(BCD Sum) BCD Sum = Sum BCD C  Carry(Sum)

BCD ADDER HARDWARE BCD Arithmetic Addend Augend Carry Out 4-bit Binary Addr K Carry In Z8 Z4 Z2 Z1 BCD Carry 0 1 1 0 4-bit Binary Adder S8 S4 S2 S1

DECIMAL ARITHMETIC OPERATIONS Addition - Identical to the BCD addition - 9’s complement and 10’s complement are identical to 1’s complement and 10’s complement, respectively