Ch. 4 Computer Arithmetic

Slides:



Advertisements
Similar presentations
CMPE 325 Computer Architecture II
Advertisements

Cosc 2150: Computer Organization Chapter 9, Part 2 Integer multiplication and division.
Integer division Pencil and paper binary division (dividend)(divisor) 1000.
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.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Fixed-Point Arithmetics: Part I
Chapter 6 Arithmetic. Addition Carry in Carry out
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
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.
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)
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.
ECE 4110– Sequential Logic Design
Computer Arithmetic Nizamettin AYDIN
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
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.
Conversion Between Lengths Positive number pack with leading zeros +18 = = Negative numbers pack with leading ones -18 =
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Multiplication of signed-operands
Figure 1.1 Block diagram of a digital computer. Functional Units.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
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:
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Basic Dividers Lecture 10. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
Mohamed Younis CMCS 411, Computer Architecture 1 CMSC Computer Architecture Lecture 11 Performing Division March 5,
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
1 Basic Dividers Lecture 9. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
CDA 3101 Spring 2016 Introduction to Computer Organization
COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers
Integer Operations Computer Organization and Assembly Language: Module 5.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
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.
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Computer Arithmetic. Integer Representation Sign-magnitude representation ’s complement representation magnitudes
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
More Binary Arithmetic - Multiplication
COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers
Multiplication and Division basics
CDA 3101 Summer 2007 Introduction to Computer Organization
William Stallings Computer Organization and Architecture 7th Edition
Computer Organization and ASSEMBLY LANGUAGE
Computer Organization and Design
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Presentation transcript:

Ch. 4 Computer Arithmetic CSE 241 Computer Organization Lecture # 10 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering

Integer Representation Integer Arithmetic Outline Integer Representation Sign-Magnitude, Two’s Complement Integer Arithmetic Negation, Addition, Subtraction Multiplication, Division Floating-Point Representation Floating-Point Arithmetic

Multiplication Example المضروب المضاعِف Running addition. 1  add & shift 0  shift only الناتج Complex. Work out a partial product for each digit. Shift the partial product appropriately. Add partial products. Need double-length result.

Unsigned Binary Multiplication Initially 0 Initially 0 Product

Flowchart for Unsigned Binary Multiplication

Execution of Example Product (143)

Signed Binary Multiplication The straight forward multiplication algorithm doesn’t work with signed numbers!! Evidence: In the previous example, suppose that M & Q are interpreted as signed numbers: M = (1011)2 which represents (-5)10 Q = (1101)2 which represents (-3)10 Applying the algorithm results in a product value of (1000 1111)2 which represents (-113)10 This result is wrong! Correct value is supposed to be (+15)10!!!!

Signed Multiplication Example: +ve Multiplier, –ve Multiplicand Sign extension Previous circuit can be used here with a couple of tweaks! (-143) 1

Signed Multiplication Algorithm #1 If multiplier  +ve & multiplicand  +ve: Follow unsigned multiplication algorithm Else if multiplier  +ve & multiplicand  -ve: Follow unsigned mult. algorithm with 2 changes: Remove the carry register (C) Use “arithmetic shift” instead of “logical shift” Else if multiplier  -ve & multiplicand  +ve: Negate (find 2’s compl. of) multiplier & multiplicand. Proceed as case 2. Else multiplier  -ve & multiplicand  -ve: Proceed as case 1.

Signed Multiplication Algorithm #2 Convert multiplicand (M) & multiplier (Q) to their absolute (positive) values |M| & |Q|. Run the unsigned multiplication algorithm on |M| & |Q| to obtain the final product (P). Adjust the sign of P (by 2’s complementation where needed) according to the following rule: sign(P) = sign(M) X sign(Q)

Signed Multiplication Algorithm #3 (Booth’s Algorithm) 0 1 0 1 1 0 1 X 0 0 1 1 1 1 0 Multiplier 0 +1 0 0 0 –1 0

Booth's Algorithm – Example 2’s complement of the multiplicand

Booth's Algorithm – Rule Multiplier Bit i Bit i–1 Version of multiplicand selected by bit i 0 0 0 × M 0 1 +1 × M 1 0 –1 × M 1 1

Booth’s Algorithm Flowchart

Example on Booth’s Algorithm Product (21)

Booth's Algorithm, –ve Multiplier

Booth’s Algorithm - Cases 1 Worst-case Multiplier +1 -1 1 Ordinary Multiplier -1 +1 1 Good Multiplier +1 -1 Booth’s Algorithm – Pros: Treats +ve and –ve multipliers uniformly. Use fewer additions if the multiplier has large blocks of 1’s. On average, has the same efficiency as the normal algorithm.

More complex than multiplication. Negative numbers are really bad! Division More complex than multiplication. Negative numbers are really bad! Based on long division. الحاصل القاسم المقسوم الباقي

Restoring Division (Positive Integers) Divisor Mn-1 · · · M0 A←A–M An-1 · · · A0 Qn-1 · · · Q0 000…0 Dividend Restore Remainder Quotient Quotient in Q Remainder in A

Restoring Division Example First cycle 7/3 Second cycle Third cycle Fourth cycle Quotient Remainder

Non-Restoring Division (Positive Integers) START A ← 0 M ← Divisor Q ← Dividend Count ← n No Yes A < 0 ? Shift Left A,Q A ← A – M Shift Left A,Q A ← A + M No Yes A < 0 ? Q0 ← 1 Q0 ← 0 Count ← Count – 1 No Yes Count = 0 ? No A < 0 ? Yes A ← A + M Quotient in Q Remainder in A END

Non-Restoring Division Example Q M = 0011 0000 0111 Initial Values 111? Shift 1101 Subtract 1110 Q0 ← 0 1011 110? Add 1100 100? 1001 Q0 ← 1 0001 001? 0010 First cycle Second cycle 7/3 Third cycle Fourth cycle Remainder Quotient

Dealing with Signed Integers Given a dividend (D) and divisor (V) where both are signed integers in the 2’s complement representation. Division can be carried out as follows: Convert D & V to their absolute (+ve) values |D| & |V|. Run either restoring or non-restoring division on |D| & |V| to obtain the quotient (Q) and the remainder (R). Adjust the sign of Q and R (by 2’s complementation where needed) according to the following rules: sign(Q) = sign(D) X sign(V) sign(R) = sign(D)