July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.

Slides:



Advertisements
Similar presentations
CMPE 325 Computer Architecture II
Advertisements

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 8 - Multiplication.
THE ARITHMETIC-LOGIC UNIT. BINARY HALF-ADDER BINARY HALF-ADDER condt Half adder InputOutput XYSC
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.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Lecture 9 Sept 28 Chapter 3 Arithmetic for Computers.
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.
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.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Jan. 2011Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.
ECE 645 – Computer Arithmetic Lecture 9: Basic Dividers ECE 645—Computer Arithmetic 4/1/08.
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.
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
Integer Conversion Between Decimal and Binary Bases Conversion of decimal to binary more complicated Task accomplished by –Repeated division of decimal.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Multiplication of signed-operands
Figure 1.1 Block diagram of a digital computer. Functional Units.
Lecture 6: Multiply, Shift, and Divide
Division Harder Than Multiplication Because Quotient Digit Selection/Estimation Can Have Overflow Condition – Divide by Small Number OR even Worse – Divide.
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.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Integer Multiplication and Division
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
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
FAMU-FSU College of Engineering 1 Part III The Arithmetic/Logic Unit.
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.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #9 – Number Representations.
CDA 3101 Spring 2016 Introduction to Computer Organization
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
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.
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.
Integer Multiplication and Division ICS 233 Computer Architecture & Assembly Language Prof. Muhamed Mudawar College of Computer Sciences and Engineering.
1. Copyright  2005 by Oxford University Press, Inc. Computer Architecture Parhami2 Figure 11.1 Multiplication of 4-bit numbers in dot notation.
Computer Architecture & Operations I
Integer Multiplication, Division Arithmetic shift
Computer Architecture & Operations I
Part III The Arithmetic/Logic Unit
Integer Multiplication and Division
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
Lecture 8: Addition, Multiplication & Division
CSCI206 - Computer Organization & Programming
Topic 3c Integer Multiply and Divide
Systems Architecture I
CDA 3101 Summer 2007 Introduction to Computer Organization
Part III The Arithmetic/Logic Unit
12/7/
Computer Architecture
Morgan Kaufmann Publishers Arithmetic for Computers
MIPS Arithmetic and Logic Instructions
Presentation transcript:

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 2 III The Arithmetic/Logic Unit Topics in This Part Chapter 9 Number Representation Chapter 10 Adders and Simple ALUs Chapter 11 Multipliers and Dividers Chapter 12 Floating-Point Arithmetic Overview of computer arithmetic and ALU design: Review representation methods for signed integers Discuss algorithms & hardware for arithmetic ops Consider floating-point representation & arithmetic

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 3 11 Multipliers and Dividers Modern processors perform many multiplications & divisions: Encryption, image compression, graphic rendering Hardware, vs programmed shift-add/sub, algorithms Topics in This Chapter 11.1 Shift-Add Multiplication 11.2 Hardware Multipliers 11.3 Programmed Multiplication 11.4 Shift-Subtract Division 11.5 Hardware Dividers 11.6 Programmed Division

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Shift-Add Multiplication Figure 11.1 Multiplication of 4-bit numbers in dot notation. z (j+1) = (z (j) + y j x 2 k ) 2 –1 with z (0) = 0 and z (k) = z |––– add –––| |–– shift right ––|

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 5 Binary and Decimal Multiplication Figure 11.2 Step-by-step multiplication examples for 4-digit unsigned numbers. Position Position ========================= x x y y ========================= z (0) y 0 x y 0 x –––––––––––––––––––––––––– 2z (1) z (1) z (1) z (1) y 1 x y 1 x –––––––––––––––––––––––––– 2z (2) z (2) z (2) z (2) y 2 x y 2 x –––––––––––––––––––––––––– 2z (3) z (3) z (3) z (3) y 3 x y 3 x –––––––––––––––––––––––––– 2z (4) z (4) z (4) z (4) ========================= Example 11.1

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 6 Two’s-Complement Multiplication Figure 11.3 Step-by-step multiplication examples for 2’s-complement numbers. Position Position ========================= x x y y ========================= z (0) y 0 x y 0 x –––––––––––––––––––––––––– 2z (1) z (1) z (1) z (1) y 1 x y 1 x –––––––––––––––––––––––––– 2z (2) z (2) z (2) z (2) y 2 x y 2 x –––––––––––––––––––––––––– 2z (3) z (3) z (3) z (3) (–y 3 x2 4 ) (–y 3 x2 4 ) –––––––––––––––––––––––––– 2z (4) z (4) z (4) z (4) ========================= Example 11.2

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Hardware Multipliers Figure 11.4 Hardware multiplier based on the shift-add algorithm.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 8 The Shift Part of Shift-Add Figure11.5 Shifting incorporated in the connections to the partial product register rather than as a separate phase.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 9 High-Radix Multipliers Radix-4 multiplication in dot notation. z (j+1) = (z (j) + y j x 2 k ) 4 –1 with z (0) = 0 and z (k/2) = z |––– add –––| |–– shift right ––| Assume k even

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 10 Tree Multipliers Figure 11.6 Schematic diagram for full/partial-tree multipliers.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 11 Array Multipliers Figure 11.7 Array multiplier for 4-bit unsigned operands.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Programmed Multiplication MiniMIPS instructions related to multiplication mult $s0,$s1# set Hi,Lo to ($s0)  ($s1); signed multu $s2,$s3# set Hi,Lo to ($s2)  ($s3); unsigned mfhi $t0# set $t0 to (Hi) mflo $t1# set $t1 to (Lo) Finding the 32-bit product of 32-bit integers in MiniMIPS Multiply; result will be obtained in Hi,Lo For unsigned multiplication: Hi should be all-0s and Lo holds the 32-bit result For signed multiplication: Hi should be all-0s or all-1s, depending on the sign bit of Lo Example 11.3

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 13 Figure 11.8 Register usage for programmed multiplication superimposed on the block diagram for a hardware multiplier. Multiplication When There Is No Multiply Instruction Example 11.4 (MiniMIPS shift-add program for multiplication)

October 2005Michael Frank, FAMU-FSU College of Engineering 14 MIPS Assembly Code for this Multiplication Algorithm shamu:move$v0,$zero# Initialize Hi to 0 move$v1,$zero# Initialize Lo to 0 addi$t2,$zero,32# Initialize repetition counter to 32. mloop:move$t0,$zero# Loop: Initialize carry to 0. andi$t1,$a1,1# LSB of multiplier to shift out. srl$a1,$a1,1# Shift the multiplier right. beqz$t1,no_add# If bit shifted out was not 0, then addu$v0,$v0,$a0#add multiplicand into Hi word, sltu$t0,$v0,$a0#and remember the carry out. no_add:andi$t1,$v0,1# LSB of Hi word to shift out. srl$v0,$v0,1# Shift Hi word of product right. sll$t0,$t0,31# Shift carry left to position 31. or$v0,$t0,$v0# OR the carry into the Hi word. srl$v1,$v1,1# Shift Lo word of product right. sll$t1,$t1,31# Shift bit left to position 31. or$v1,$t1,$v1# OR the bit into the Lo word. addi$t2,$t2,-1# Decrement loop counter. bnez$t2,mloop# Continue while counter is nonzero. jr$ra# Return product=($v0,$v1) to caller.

October 2005Michael Frank, FAMU-FSU College of Engineering 15 C language equivalent unsigned long shamu(unsigned int mcand, unsigned int mer) { unsigned int Hi,Lo,carry,bit,counter; Lo = Hi = 0; /* Initialize product registers to 0. */ counter = 32;/* Initialize repetition counter to 32. */ do {/* Repeat the following loop: */ carry = 0;/* Initialize carry-out bit to 0. */ bit = mer & 1; /* t1 := LSB of m'er. */ mer >>= 1;/* Shift m'er right by 1. */ if (bit) {/* If low bit of multiplier was 1, then */ Hi += mcand; /* Add mcand into Hi */ carry = (Hi < mcand);/* Carry out from add */ }/* END IF. */ bit = Hi & 1;/* LSB of Hi */ Hi = (carry > 1);/* Shift carry into Hi */ Lo = (bit > 1);/* Shift into Lo */ counter--;/* Decrement counter. */ } while (counter > 0); return ((unsigned long)Hi)<<32 & Lo;/* Return 64-bit result. */ } /* END FUNCTION shamu() */

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Shift-Subtract Division Figure11.9 Division of an 8-bit number by a 4-bit number in dot notation. z (j) = 2z (j  1)  y k  j x 2 k with z (0) = z and z (k) = 2 k s | shift | |–– subtract ––|

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 17 Integer and Fractional Unsigned Division Figure Division examples for binary integers and decimal fractions. Position Position –1 –2 –3 –4 –5 –6 –7 –8 =================================================== z z x x =================================================== z (0) z (0) z (0) z (0) –y 3 x y 3 =1–y –1 x y –1 =3 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (1) z (1) z (1) z (1) –y 2 x y 2 =0–y –2 x y –2 =5 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (2) z (2) z (2) z (2) –y 1 x y 1 =1–y –3 x y –3 =2 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (3) z (3) z (3) z (3) –y 0 x y 0 =1–y –4 x y –4 =8 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (4) z (4) s s y y =================================================== Example 11.5

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 18 Division with Same-Width Operands Figure Division examples for 4/4-digit binary integers and fractions. Position Position –1 –2 –3 –4 –5 –6 –7 –8 =================================================== z z x x =================================================== z (0) z (0) z (0) z (0) –y 3 x y 3 =0–y –1 x y –1 =0 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (1) z (1) z (1) z (1) –y 2 x y 2 =0–y –2 x y –2 =1 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (2) z (2) z (2) z (2) –y 1 x y 1 =1–y –3 x y –3 =1 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (3) z (3) z (3) z (3) –y 0 x y 0 =0–y –4 x y –4 =0 ––––––––––––––––––––––––––––––––––––––––––––––––––––– z (4) z (4) s s y y =================================================== Example 11.6

October 2005Michael Frank, FAMU-FSU College of Engineering 19 C++ function for division of unsigned 32-bit integers unsigned int myDivide // DEFINE FUNCTION myDivide(): (unsigned int dividend, // Argument 0: Number to be divided. unsigned int divisor, // Argument 1: Number to divide it by. unsigned int &remainder) // Argument 2: Place to put remainder. {unsigned int quotient = 0; // Quotient: Initially zero. int position = 0; // Bit position: Initially zero. while (!(divisor & (1<<31))) {// While divisor MSB is empty, position++; // Increment bit position, divisor <<= 1; } // & shift divisor left. do{quotient <<= 1; // Repeatedly, make room for quotient bit; if (dividend >= divisor) { // if we can do a subtraction here, dividend -= divisor; // then do it, quotient |= 1; } // and set quotient bit to 1; divisor >>= 1; } // shift divisor right to a new position; while (--position >= 0); // decrement pos and continue while >=0 remainder = dividend; // Remainder is the remaining dividend. return quotient;} // Return quotient (& remainder).

October 2005Michael Frank, FAMU-FSU College of Engineering 20 Equivalent MIPS assembly for 32-bit unsigned division myDivide: move$v0, $zero # quotient := 0; move$t0, $zero # position := 0; leftShift: and$t1, $a1, 0x # while (divisor & 0x bne$t1, $zero, doTop # != 0) { addi$t0, $t0, 1 # position++; sll$a1, $a1, 1 # divisor <<= 1; bleftShift # } doTop: sll$v0, $v0, 1 # do { quotient <<= 1; sltu$t1, $a0, $a1 # $t4 := (dividend < divisor) bne$t1, $zero, endIf # if ($t4 == 0) {// d’dend >= d’sor subu$a0, $a0, $a1 # dividend -= divisor; or$v0, $v0, 1 # quotient |= 1; } endIf: srl$a1, $a1, 1 # divisor >>= 1; addi$t0, $t0, -1 # position--; bgez$t0, doTop # } while (position >= 0); endFor: sw$a0, 0($a2) # rem := remainder; jr$ra # return.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 21 Signed Division Method 1 (indirect): strip operand signs, divide, set result signs Dividend Divisor QuotientRemainder z = 5 x = 3  y = 1 s = 2 z = 5 x = –3  y = –1 s = 2 z = –5 x = 3  y = –1 s = –2 z = –5 x = –3  y = 1 s = –2 Method 2 (direct 2’s complement): develop quotient with digits –1 and 1, chosen based on signs, convert to digits 0 and 1 Restoring division: perform trial subtraction, choose 0 for q digit if partial remainder negative Nonrestoring division: if sign of partial remainder is correct, then subtract (choose 1 for q digit) else add (choose –1)

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Hardware Dividers Figure Hardware divider based on the shift-subtract algorithm.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 23 The Shift Part of Shift-Subtract Figure Shifting incorporated in the connections to the partial remainder register rather than as a separate phase.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 24 High-Radix Dividers Radix-4 division in dot notation. z (j) = 4z (j  1)  (y k  2j+1 y k  2j ) two x 2 k with z (0) = z and z (k/2) = 2 k s | shift | |––––––– subtract –––––––| Assume k even

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 25 Array Dividers Figure Array divider for 8/4-bit unsigned integers.

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide Programmed Division MiniMIPS instructions related to division div $s0,$s1# Lo = quotient, Hi = remainder divu $s2,$s3# unsigned version of division mfhi $t0# set $t0 to (Hi) mflo $t1# set $t1 to (Lo) Compute z mod x, where z (singed) and x > 0 are integers Divide; remainder will be obtained in Hi if remainder is negative, then add |x| to ( Hi ) to obtain z mod x else Hi holds z mod x Example 11.7

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 27 Figure Register usage for programmed division superimposed on the block diagram for a hardware divider. Division via Repeated Subtractions Example 11.8 (MiniMIPS shift-add program for division)

July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 28 Divider vs Multiplier: Hardware Similarities Figure 11.12Figure 11.4 Figure 11.14Figure 11.7 Turn upside-down