King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.

Slides:



Advertisements
Similar presentations
Multiplication and Division
Advertisements

Arithmetic for Computers
Datorteknik IntegerMulDiv bild 1 MIPS mul/div instructions Multiply: mult $2,$3Hi, Lo = $2 x $3;64-bit signed product Multiply unsigned: multu$2,$3Hi,
CMPE 325 Computer Architecture II
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 8 - Multiplication.
Division CPSC 321 Computer Architecture Andreas Klappenecker.
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
CMPT 334 Computer Organization Chapter 3 Arithmetic for Computers [Adapted from Computer Organization and Design 5 th Edition, Patterson & Hennessy, ©
Lecture Objectives: 1)Perform binary division of two numbers. 2)Define dividend, divisor, quotient, and remainder. 3)Explain how division is accomplished.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Integer Multiplication and DivisionICS 233 – KFUPM © Muhamed Mudawar slide 1 Multiplicand and HI are sign-extended  Sign is the sign of the result Signed.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
361 div.1 Computer Architecture ECE 361 Lecture 7: ALU Design : Division.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Computer Organization Multiplication and Division Feb 2005 Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann.
Chap 3.3~3.5 Construction an Arithmetic Logic Unit (ALU) Jen-Chang Liu, Spring 2006.
Integer Multiplication and Division
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Lecture Objectives: 1)Explain the relationship between addition and subtraction with twos complement numbering systems 2)Explain the concept of numeric.
Multiplication CPSC 252 Computer Organization Ellen Walker, Hiram College.
ECE 4110– Sequential Logic Design
Computer Arithmetic Nizamettin AYDIN
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
Computer Arithmetic II Instructor: Mozafar Bag-Mohammadi Spring 2006 University of Ilam.
Multiplication of signed-operands
July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.
Lecture 6: Multiply, Shift, and Divide
Computer Arithmetic II Instructor: Mozafar Bag-Mohammadi Ilam University.
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Cs 152 l6 Multiply 1 DAP Fa 97 © U.C.B. ECE Computer Architecture Lecture Notes Multiply, Shift, Divide Shantanu Dutt Univ. of Illinois at.
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Integer Multiplication and Division
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Csci 136 Computer Architecture II – Multiplication and Division
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Arithmetic: Part II.
Division Check for 0 divisor Long division approach – If divisor ≤ dividend bits 1 bit in quotient, subtract – Otherwise 0 bit in quotient, bring down.
CDA 3101 Spring 2016 Introduction to Computer Organization
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
Integer Operations Computer Organization and Assembly Language: Module 5.
Integer Multiplication and Division ICS 233 Computer Architecture & Assembly Language Prof. Muhamed Mudawar College of Computer Sciences and Engineering.
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Computer Architecture & Operations I
Multiplication and Division basics
CHAPTER 18 Circuits for Arithmetic Operations
Computer Architecture & Operations I
Integer Multiplication and Division
MIPS mul/div instructions
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers
Lecture 8: Binary Multiplication & Division
Multiplication & Division
CDA 3101 Summer 2007 Introduction to Computer Organization
CDA 3101 Spring 2016 Introduction to Computer Organization
Lecture 8: Addition, Multiplication & Division
King Fahd University of Petroleum and Minerals
Lecture 8: Addition, Multiplication & Division
CSCE 350 Computer Architecture
Topic 3c Integer Multiply and Divide
CDA 3101 Summer 2007 Introduction to Computer Organization
Computer Architecture
October 15 Chapter 4 – Multiplication/Division Go to the State Fair!
CHAPTER 18 Circuits for Arithmetic Operations
MIPS Arithmetic and Logic Instructions
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Presentation transcript:

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 1 COE 308 Lectures 5: Multiplication & Division

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 2 COE 308 Multiplication Algorithm School Age Algorithm 852 x x 852 x x 852 x x 852 x Multiply the product by the order of the digit (x 10 i ) Single Digit Multiplication Multiplication by a power of the base (10 i ) is a Shift Left by i positions Multiple Additions Algorithm: Compute Partial Products Multiply Multiplicand by EACH DIGIT of Multiplier Add Partial Products

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 3 COE 308 Multiplication in Binary x x x x x x x x x x x Because there are only two digits in binary (0 and 1). The multiplication algorithm becomes only: Add the Shifted Multiplicands Shift Multiplicand Multiply Shifted Multiplicand by 1 or 0 Easy to Implement A x 1 = A; A x 0 = 0 Addition of many operands? Issue: How to add more than two operands at the same time ?

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 4 COE 308 Adding Partial Products Issue: How to add more than two operands at the same time ? bits Multiplier Multiplicand h (0 on 32 bits) Uses many Adders Need circuit that uses one to few adders because of size limitations Parallel Multipliers are used in high performance, multiplication intensive, architectures like DSP (Digital Signal Processing). TOO EXPENSIVE

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 5 COE 308 Iterative Solution Full Parallel Multiplier is too expensive Solution Iteratively add the partial products Advantages Uses ONE Adder Only Inconvenients Much Slower than Parallel Multiplication Circuit

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 6 COE 308 First Multiplication Algorithm Shift Right Shift Left Multiplicand Multiplier 64-bit ALU Product Write 64 bits 32 bits Control test Shift the Multiplicand Left to realize the multiplication by the order of the digit Shift the Multiplier right to get out each digit LSB first and MSB last Control the write of the product register to only add partial products corresponding to a multiplier digit equal to 1 Add the product register content to every potential partial product (shifted multiplicand) all the time. Result is only written when appropriate

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 7 COE 308 First Multiplication Algorithm(2) Start Bit 0 of Multiplier = 0 ? Product  Product + Multiplicand Shift Left Multiplicand with 1 bit Shift Right Multiplier with 1 bit 32 nd Repetition? Done =0=1 No: < 32 repetitions Yes: 32 repetitions

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 8 COE 308 Multiplication Circuit Improvement Current Circuit has 64-bits Multiplier Register used to shift the Multiplier. –Shifting the Multiplier means inserting 0s (known value). Reserving bits for holding known values is a waste of resources –Anytime, Register contains 32 data bits and 32 0s. –100% overhead just to shift 64-bits Adder is not necessary because: –Addition is done between two 32 bits operands Either add lower bits of product with lower 0s of the shifted multiplier Or add the higher bits of the product which are 0s with the leading bits of the shifted multiplicand Need to Reduce the cost of the Multiplication Circuit

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 9 COE 308 Analogy Multiplication Method is the same. Two Ways of Implementing the same algorithm 1.Shift the Multiplicand register forward and do not shift the Product register (what we have seen so far) 2.Shift the Product register backward and do not shift the Multiplicand register (the other method) Similar to having two methods of making a moving scene in a movie

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 10 COE 308 Movie Making Tips Is The Car Moving Forward or the Trees moving Backward ???

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 11 COE 308 Method 1 The Car is Moving Forward The Camera/Observer is attached to the car

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 12 COE 308 Method 2 The Car is a Fake Car. The Camera/Observer and the Fake Car are both fixed The trees are pictures fixed on a moving panel

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 13 COE 308 Shifting Backwards x x     Shift Multiplicand Left No Shift for the Product No Shift for the Multiplicand Shift the Product Right (Backward) MultiplicandMultiplier Product Product Initial Mcand x 1 Shiftd 0 bits Mcand x 1 Shiftd 1 bits Mcand x 0 Mcand x 1 Shiftd 4 bits Product Initial Mcand x 1 Sh. Product Right Mcand x 1 Sh. Product Right Mcand x 0 Sh. Product Right Mcand x 0 Sh. Product Right Mcand x 1

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 14 COE 308 Shift Right Multiplicand Multiplier 32-bit ALU Product Write 64 bits 32 bits Control test Second Multiply Algorithm Shift Right

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 15 COE 308 Start Bit 0 of Multiplier = 0 ? Product[63:32]  Product[63:32] + Multiplicand Shift Right Product with 1 bit Shift Right Multiplier with 1 bit 32 nd Repetition? Done =0=1 No: < 32 repetitions Yes: 32 repetitions Second Multiply Algorithm (2)

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 16 COE 308 Another Improvement –The lower 32-bits 0s are shifted out as the Product register is shifted right –Only the Upper 32-bits are added to the Multiplicand –Initialize the 64-bit Product Register with 0s In Second Multiplication Algorithm: Merge the lower 32-bits of Product Register with Multiplier Register

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 17 COE 308 Third Multiply Algorithm Multiplier Register merged with lower 32 bits of Product register Multiplicand 32-bit ALU Product Write 64 bits 32 bits Control test Shift Right

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 18 COE 308 Third Multiply Algorithm (2) Start Bit 0 of Product = 0 ? Product[63:32]  Product[63:32] + Multiplicand Shift Right Product with 1 bit 32 nd Repetition? Done =0=1 No: < 32 repetitions Yes: 32 repetitions

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 19 COE 308 Signed Multiplication Convert multiplier and multiplicand into positive numbers Perform the multiplication Compute the sign of the product Apply the sign to the product by either complementing the product ( 0)

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 20 COE 308 Booth’s Algorithm Principle: Minimization of Intermediate Additions by Virtually reducing multiplier End of run Middle of run Beginning of run ii+3i+2i+1 Normal Method: Product = Product + Mcand.(2 i i i i ) Booth’s Method: Product = Product + Mcand. (2 i+4 -2 i ) Current BitBit to the rightRunOperation 10Beginning of a run of 1sSubtract Multiplicand 11Middle of a run of 1sDo Nothing 01End of a run of 1sAdd Multiplicand 00Middle of run of 0sDo nothing

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 21 COE 308 Multiplication in MIPS Separate pair of 32 bits registers to contain the 64-bit product –Hi and Lo: 32 bits each. Result of multiplication instructions always in Hi:Lo –2 instructions to move the result from Hi/Lo to MIPS registers: mflo and mfhi 2 Multiply instructions –mult: signed multiplication –multu: unsigned multiplication

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 22 COE 308 Division < > 21 Find biggest digit d (from 1 to 9) which satisfies: 82 >= 21 x d Determine d using: Intuition (Guessing) when performed by a Human Algorithm that increases d until Either d x 21 > 82; use (d-1) Or d = 9 82 > 21x1 82 > 21x2 82 > 21x3 82 < 21x 4 Use (4-1) = > 21x1 …………………… 197 > 21x8 197 > 21x9 Use Select One digit from Dividend to compare to Divisor Smaller than Divisor, Consider Two digits

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 23 COE 308 Division Algorithm (in Decimal) M = Leftmost Digit of Dividend M >= Divisor Shift Left Next Digit of Dividend into M No Yes d = 1 Shift Left Next Digit of Dividend into M M <= d x Divisor d = 9 No d = d + 1 No d = d - 1 M = M – (d x Divisor) Shift in d into Q No More Digits in Dividend Yes No M: Remainder Q: Quotient Start Define M: temporary storage Define Q: Quotient Q = 0 Done

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 24 COE 308 Division in Binary Many steps before finding a number > Divisor Presence of leading 0s disturbs the conventional algorithm Extract digits from Dividend and Shift them to align them with Divisor Every step the Extracted Digits are compared to the Divisor: If Divisor x 1 > Extracted Digits  Shift in 0 in the Quotient If Divisor x 1 <= Extracted Digits  Shift in 1 in the Quotient In binary, d can only take the value 0 or 1. Means: Divisor x d <= Extracted Digits from Dividend  d = 1 Quotient Register: Shift Left Serial In from LSB Method of Extracting Digits from Dividend not Practical in Context of Logic Circuits

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 25 COE 308 Forced Alignment To Force the Alignment of the Dividend and the Divisor: Multiply the Divisor by 2 n (Shift Left by n), n being the number of bits of both the Dividend and the Divisor Shift right (divide by 2) the Divisor until Divisor <= Dividend < 0>= 0 Rest of the Algorithm Remains the Same

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 26 COE 308 First Division Algorithm Shift Left Shift right Divisor Quotient 64-bit ALU Remainder Write 64 bits 32 bits Control test

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 27 COE 308 First Division Algorithm (2) Start Test Remainder Shift Quotient to left setting the new rightmost bit to 1 Shift Right Divisor with 1 bit 33 rd Repetition? Done Remainder < 0 No: < 33 repetitionsYes: 33 repetitions Remainder  Remainder - Divisor Remainder ≥ 0 Restore original value of Remainder Remainder  Remainder + Divisor Shift Quotient to left setting the new rightmost bit to 1

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 28 COE 308 Division Algorithm Improvement Current Circuit has 64-bits Divisor Register used to shift the Divisor. –Shifting the Divisor means inserting 0s (known value). Reserving bits for holding known values is a waste of resources –Anytime, Register contains 32 data bits and 32 0s. –100% overhead just to shift 64-bits ALU is not necessary because: –Subtraction is done between two 32 bits operands (after alignment of Divisor and Dividend) Need to Reduce the cost of the Division Circuit

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 29 COE 308 Shifting Dividend Forward Shifting the Divisor Backward (Right) and Fixing the Dividend/Remainder is equivalent to: Fixing the Divisor and Shifting the Dividend/Remainder Forward (Left) Similar to the Analogy made in improving the Multiplication Algorithm In Second Method: Dividend/Remainder Register still 64-bits, initialized with Dividend aligned right with upper 32-bits initialized to 0 Divisor Register is reduced to 32-bits and is not shifted.

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 30 COE 308 Second Division Algorithm Shift Left Divisor Quotient 32-bit ALU Remainder Write 64 bits 32 bits Control test Shift Left

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 31 COE 308 Another Improvement In Second Algorithm: Remainder Register upper 32-bits initialized to 0s Remainder Register is shifted left 32 times. 0s are inserted in the LSB of the Remainder Register Lower 32 bits end-up with 0s Quotient Register: 32-bit LSB serial-in left shift register Data is progressively shifted-in in the Quotient Register Merge the lower 32-bits of Remainder Register with Quotient Register

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 32 COE 308 Final Division Algorithm Divisor 32-bit ALU Remainder Write 64 bits 32 bits Control test Shift Right Shift Left

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Multiplication & Division 33 COE 308 Division in MIPS Separate pair of 32 bits registers to contain the 64-bit remainder: –Hi and Lo: 32 bits each. –Lo: Contains Quotient –Hi: Contains Remainder –2 instructions to move the result from Hi/Lo to MIPS registers: mflo and mfhi 2 Divide instructions –div: signed division –divu: unsigned division