05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.

Slides:



Advertisements
Similar presentations
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
Advertisements

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
Chapter 2 Instructions: Language of the Computer Part III.
Computer Architecture ECE 361 Lecture 6: ALU Design
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 8 - Multiplication.
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.
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.
Lecture 9 Sept 28 Chapter 3 Arithmetic for Computers.
Fixed-Point Arithmetics: Part I
Arithmetic IV CPSC 321 Andreas Klappenecker. Any Questions?
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.
Integer Multiplication and Division
CS141-L3-1Tarun Soni, Summer ‘03 More ALUs and floating point numbers  Today: The rest of chap 4:  Multiplication, Division and Floating point numbers.
Contemporary Logic Design Arithmetic Circuits © R.H. Katz Lecture #24: Arithmetic Circuits -1 Arithmetic Circuits (Part II) Randy H. Katz University of.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Chapter Four Arithmetic and Logic Unit
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Multipliers CPSC 321 Computer Architecture Andreas Klappenecker.
1 Lecture 4: Arithmetic for Computers (Part 4) CS 447 Jason Bakos.
ECE 232 L9.Mult.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 9 Computer Arithmetic.
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.
ECE232: Hardware Organization and Design
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Lecture 6: Multiply, Shift, and Divide
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
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.
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
Mohamed Younis CMCS 411, Computer Architecture 1 CMSC Computer Architecture Lecture 11 Performing Division March 5,
CS152 / Kubiatowicz Lec6.1 2/12/03©UCB Spring 2003 CS152 Computer Architecture and Engineering Lecture 6 Multiply, Divide, Shift February 12, 2003 John.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Arithmetic: Part II.
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu ( )
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.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
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 System Design Lecture 3
Computer Architecture & Operations I
Computer Architecture & Operations I
Integer Multiplication and Division
MIPS mul/div instructions
Single Bit ALU 3 R e s u l t O p r a i o n 1 C y I B v b 2 L S f w d O
Morgan Kaufmann Publishers Arithmetic for Computers
Part II : Lecture III By Wannarat.
CS 314 Computer Organization Fall Chapter 3: 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
CS352H: Computer Systems Architecture
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Topic 3c Integer Multiply and Divide
CDA 3101 Summer 2007 Introduction to Computer Organization
Computer Arithmetic Multiplication, Floating Point
A.R. Hurson 323 CS Building, Missouri S&T
Computer Architecture EECS 361 Lecture 6: ALU Design
Presentation transcript:

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir2 mult $s2, $s3 # hi||lo = $s2 * $s3 MIPS Multiply Instruction op rs rt rd shamt funct $s2 $s $s2 $s  Low-order word of the product is placed in processor dedicated register lo and the high-order word is placed in processor register hi  mult uses signed integers and result is a signed 64-bit number. Overflow is checked in software  MIPS uses multu for unsigned products

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir3  Multiplication is more complicated than addition - via shifting and addition 0010 ten (multiplicand) x 1011 ten (multiplier) (partial product 0000 array) 0010  The product needs to be moved to general purpose registers to become available for other operations. Instructions mfhi $s0 and mflo $s5 are provided for this.  mfhi $s0  mflo $s5 Multiply Instruction $s $s ten (product)  m bits  n bits = m+n bit product 32+32=64 bits double precision product produced – more time to compute

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir4  Binary numbers make it easy: 0 => place 0s ( 0 x multiplicand) in the proper place 1 => place a copy of multiplicand in the proper place Multiply Instruction ………… …………… … s 32-bit multiplicand  at each stage shift the multiplicand left ( x 2)  use next LSB of b to determine whether to add in shifted multiplicand  accumulate 2n bit partial product at each stage  The process is repeated 32 times in MIPS

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir5 Unsigned shift-add multiplier (version 1)  64-bit Multiplicand reg., 64-bit ALU, 64-bit Product reg. (initialized to 0 s), 32-bit multiplier register ………… …………… … s 32-bit multiplicand If Multiplier0 = 1

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir6 Multiply Algorithm Version 1 u Multiplier Multiplicand Product two x 1001 two

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir7 Observations on Multiply Version 1  1 clock cycle => 100 clocks per multiply Ratio of multiply to add 1:5 to 1:100  1/2 bits in multiplicand always 0 => 64-bit adder is wasted  0’s inserted in right of multiplicand as it is shifted left => least significant bits of product never changed once formed  Instead of shifting multiplicand to left, shift product to right?

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir8 Multiply Hardware Version 2  32-bit Multiplicand register, 32 -bit ALU, 64-bit Product register, 32-bit Multiplier register If Multiplier0 = 1

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir9 Multiply Algorithm Version 2  Multiplicand stay’s still and product moves right  Product register wastes space that exactly matches size of multiplier  So we can combine Multiplier register and Product register

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir10 Multiply Hardware Version 3  32-bit Multiplicand register, 32 -bit ALU, 64-bit Product register, (0-bit Multiplier register)  2 steps per bit because Multiplier & Product combined  MIPS registers Hi and Lo are left and right half of Product  Gives us MIPS instruction MultU ………… …………… … s 32-bit multiplier If Product0=1

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir11 Multiply Algorithm Version 3 u Iter. Multiplicand Product add shift shift shift add shift two x 1001 two

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir12 Multiplication of signed integers  What about signed multiplication?  Easiest solution is to make both positive & remember whether to complement product when done (leave out the sign bit, run for 31 steps)  Apply definition of 2’s complement. Need to sign-extend partial products and subtract at the end  Booth’s Algorithm is elegant way to multiply signed numbers using same hardware as before and save cycles  It can handle multiple bits at a time, thus it is faster

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir shift (0 in multiplier) add (1 in multiplier) shift (0 in multiplier)  Example 2 x 6 = 0010 x 0110 two : 0010 x 0110 Motivation for Booth’s Algorithm  ALU with add or subtract gets same result in more than one way: 6= – = – =

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir14 Motivation for Booth’s Algorithm  For example 0010 x shift (0 in multiplier) – 0010 sub (first 1 in multiplier) shift (mid string of 1s) add (prior step had last 1)  Booth’s algorithm handles signed products by looking at the strings of 1 s

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir15 Now the test in the algorithm depends on two bits. Results are placed in the left half of the product register. Current BitBit to the RightExplanationExampleOp 1 0Begins run of 1s subtract 1 1Middle of run of 1s no op 0 1End of run of 1s add 0 0Middle of run of 0s no op Originally for Speed (when shift was faster than add)  Replace a string of 1 s in multiplier with an initial subtract when we first see a 10 and then later add for the first 01 Booth’s Algorithm

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir16 Booths Example (2 x 7)  1a. P = P - m shift P (sign extend)  1b > nop, shift  > nop, shift  > add  4a  shift  4b done OperationMultiplicandProduct registernext operation? 0. initial value > subtract mythical bit

05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir17 Booths Example (2 x -3) ( two ) 1a. P = P - m shift P (sign ext) 1b > add multiplicand a shift P and sign ext. 2b > sub multiplicand a shift and sign ext 3b > no op 4a shift 4b done OperationMultiplicandProductnext? 0. initial value > subtract