Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.

Slides:



Advertisements
Similar presentations
Comparator.
Advertisements

ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Arithmetic Operations and Circuits
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
ECE 331 – Digital System Design
1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris.
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
Chapter 6 Arithmetic. Addition Carry in Carry out
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
Lecture 8 Arithmetic Logic Circuits
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Design of Arithmetic Circuits – Adders, Subtractors, BCD adders
Overview Iterative combinational circuits Binary adders
ECE 301 – Digital Electronics
ECE 301 – Digital Electronics
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 4 – Arithmetic Functions Logic and Computer.
Arithmetic.
CS 105 Digital Logic Design
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.
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
3-1 Chapter 3 - Arithmetic Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer Architecture.
Logical Circuit Design Week 8: Arithmetic Circuits Mentor Hamiti, MSc Office ,
Arithmetic Chapter 4.
Arithmetic Chapter 4.
Digital Arithmetic and Arithmetic Circuits
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
5-1 Programmable and Steering Logic Chapter # 5: Arithmetic Circuits.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Multiplication of signed-operands
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
Computer Organization Department of CSE, SSE Mukka Chapter 6 : ARITHMETIC | Website for students | VTU NOTES.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 8 Arithmetic.
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
Combinational Circuits
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Computer Architecture Lecture 16 Fasih ur Rehman.
ECE 331 – Digital System Design Multi-bit Adder Circuits, Adder/Subtractor Circuit, and Multiplier Circuit (Lecture #12)
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
CS/EE 3700 : Fundamentals of Digital System Design Chris J. Myers Lecture 5: Arithmetic Circuits Chapter 5 (minus 5.3.4)
1 Chapter 4 Combinational Logic Logic circuits for digital systems may be combinational or sequential. A combinational circuit consists of input variables,
Addition, Subtraction, Logic Operations and ALU Design
CHAPTER 2 Digital Combinational Logic/Arithmetic Circuits
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
Integer Operations Computer Organization and Assembly Language: Module 5.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Logic Design (CE1111 ) Lecture 4 (Chapter 4) Combinational Logic Prepared by Dr. Lamiaa Elshenawy 1.
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Addition and multiplication1 Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
Gunjeet Kaur Dronacharya Group of Institutions. Binary Adder-Subtractor A combinational circuit that performs the addition of two bits is called a half.
Arithmetic UNIT-V.
Addition and Subtraction
UNIT-6 Arithmetic Course code: 10CS46 Prepared by :
Unsigned Multiplication
King Fahd University of Petroleum and Minerals
Arithmetic Circuits (Part I) Randy H
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Presentation transcript:

Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface

1 Number representation Integers are represented as binary vectors Suppose each word consists of 32 bits, labeled 0… MSB (most significant bit) LSB (least) V(b) = b b b b b Value of the binary vector interpreted as unsigned integer is: More generally in N bits,

2 Number representation (contd..)  We need to represent both positive and negative integers.  Three schemes are available for representing both positive and negative integers:  Sign and magnitude.  1’s complement.  2’s complement.  All schemes use the Most Significant Bit (MSB) to carry the sign information:  If MSB = 0, bit vector represents a positive integer.  If MSB = 1, bit vector represents a negative integer.

3 Number representation (contd..)  Sign and Magnitude:  Lower N-1 bits represent the magnitude of the integer  MSB is set to 0 or 1 to indicate positive or negative  1’s complement:  Construct the corresponding positive integer (MSB = 0)  Bitwise complement this integer  2’s complement:  Construct the 1’s complement negative integer  Add 1 to this

4 Number representation (contd..) b 3 b 2 b 1 b 0 Sign and magnitude 1's complement2's complement BValues represented

5 Number representation (contd..) Range of numbers that can be represented in N bits Unsigned: Sign and magnitude: One’s complement:: Two’s complement:: 0 has both positive and negative representation 0 has a single representation, easier to add/subtract.

6 Value of a bit string in 2’s complement How to determine the value of an integer given: Integer occupies N bits. 2’s complement system is in effect. Binary vector b represents a negative integer, what is V(b). Write b = 1 b n-2 b n-2 b n b 1 b 0 Then V(b) = -2 n-1 + b n-2 2 n-2 + b n-3 2 n b b b (v(b) = -2 n-1 + b n-2 2 n-2 + b n-3 2 n b b b showing negative and positive parts of the expression ) So, in 4 bits, 1011 is v(1011) = = -5

7 Addition of positive numbers Carry-out Add two one-bit numbers To add multiple bit numbers: Add bit pairs starting from the low-order or LSB (right end of bit vector) Propagate carries towards the high-order or MSB (left end of bit vector)

8 Addition and subtraction of signed numbers  We need to add and subtract both positive and negative numbers.  Recall the three schemes of number representation.  Sign-and-magnitude scheme is the simplest representation, but it is the most awkward for addition and subtraction operations.  2’s complement if the most efficient method for performing addition and subtraction of signed numbers.

9 Addition and subtraction of signed numbers (contd..) Consider addition modulo 16 operation Example: (7+4) modulo 16: -Locate 7 on the circle. -Move 4 units in the clockwise direction. -Arrive at the answer 11. Example: (9+14) modulo 16: -Locate 9 on the circle. -Move 14 units in the clockwise direction. -Arrive at the answer

10 Addition and subtraction of signed numbers (contd..) Different interpretation of mod 16 circle: - Values 0 through 15 represented by 4-bit binary vectors. - Reinterpret the binary numbers from –8 through 7 in 2’s complement method. Example: Add +7 to –3 -2’s complement of +7 is ’s complement of –3 is Locate 0111 on the circle. -Move 1101 (13) steps clockwise. -Arrive at 4(0100) which is the answer Ignore carry out

11 Rules for addition and subtraction of signed numbers in 2’s complement form  To add two numbers:  Add their n-bit representations.  Ignore the carry out from MSB position.  Sum is the algebraically correct value in the 2’s complement representation as long as the answer is in the range –2 n-1 through +2 n-1 –1.  To subtract two numbers X and Y ( X-Y ):  Form the 2’s complement of Y.  Add it to X using Rule 1.  Result is correct as long as the answer lies in the range –2 n-1 through +2 n-1 –1.

12 Overflow in integer arithemtic  When the result of an arithmetic operation is outside the representable range an arithmetic overflow has occurred.  Range is –2 n-1 through +2 n-1 –1 for n-bit vector.  When adding unsigned numbers, carry-out from the MSB position serves as the overflow indicator.  When adding signed numbers, this does not work.  Using 4-bit signed numbers, add +7 and +4:  Result is 1011, which represents –5.  Using 4-bit signed integers, add –4 and –6:  Result is 0110, which represents +6.

13 Overflow in integer arithmetic (contd..)  Overflow occurs when both the numbers have the same sign.  Addition of numbers with different signs cannot cause an overflow.  Carry-out signal from the MSB (sign-bit) position is not a sufficient indicator of overflow when adding signed numbers.  Detect overflow when adding X and Y :  Examine the signs of X and Y.  Examine the signs of the result S.  When X and Y have the same sign, and the sign of the result differs from the signs of X and Y, overflow has occurred.

14 Addition/subtraction of signed numbers s i = c i +1 = Y Example: 1 0 == Legend for stagei x i y i Carry-inc i Sums i Carry-outc i+1 X Z x i y i s i Carry-out c i+1 Carry-in c i x i y i c i x i y i c i x i y i c i x i y i c i x i y i c i  = +++ y i c i x i c i x i y i ++ At the i th stage: Input: c i is the carry-in Output: s i is the sum c i+1 carry-out to (i+1) st state

15 Addition logic for a single stage Full adder (FA) c i c i1+ s i Sum Carry y i x i c i y i x i c i y i x i x i c i y i s i c i1+ Full Adder (FA): Symbol for the complete circuit for a single stage of addition.

16 n -bit adder Cascade n full adder (FA) blocks to form a n -bit adder. Carries propagate or ripple through this cascade, n -bit ripple carry adder. FA c 0 y 1 x 1 s 1 FA c 1 y 0 x 0 s 0 FA c n1- y n1- x n1- c n s n1- Most significant bit (MSB) position Least significant bit (LSB) position Carry-in c 0 into the LSB position provides a convenient way to perform subtraction.

17 kn -bit adder kn -bit numbers can be added by cascading k n -bit adders. n-bit c 0 y n x n s n c n y 0 x n1- s 0 c kn s k1-  n x 0 y n1- y 2n1- x 2n1- y kn1- s n1- s 2n1- s kn1- x kn1- adder n-bit adder n-bit adder Each n -bit adder forms a block, so this is cascading of blocks. Carries ripple or propagate through blocks, Blocked Ripple Carry Adder

18 n -bit subtractor FA 1 y 1 x 1 s 1 FA c 1 y 0 x 0 s 0 FA c n1- y n1- x n1- c n s n1- Most significant bit (MSB) position Least significant bit (LSB) position Recall X – Y is equivalent to adding 2’s complement of Y to X. 2’s complement is equivalent to 1’s complement + 1. X – Y = X + Y + 1 2’s complement of positive and negative numbers is computed similarly.

19 n -bit adder/subtractor FA 1 y 1 x 1 s 1 FA c 1 y 0 x 0 s 0 FA c n1- y n1- x n1- c n s n1- Most significant bit (MSB) position Least significant bit (LSB) position FA c 0 y 1 x 1 s 1 FA c 1 y 0 x 0 s 0 FA c n1- y n1- x n1- c n s n1- Most significant bit (MSB) position Least significant bit (LSB) position Adder inputs: x i, y i, c o =0 Subtractor inputs: x i, y i, c o =1

20 n -bit adder/subtractor (contd..) Add/Sub control n-bit adder x n1- x 1 x 0 c n s n1- s 1 s 0 c 0 y n1- y 1 y 0 Add/sub control = 0, addition. Add/sub control = 1, subtraction.

21 Detecting overflows  Overflows can only occur when the sign of the two operands is the same.  Overflow occurs if the sign of the result is different from the sign of the operands.  Recall that the MSB represents the sign.  x n-1, y n-1, s n-1 represent the sign of operand x, operand y and result s respectively.  Circuit to detect overflow can be implemented by the following logic expressions:

22 Computing the add time Consider 0 th stage: x0x0 y0y0 c0c0 c1c1 s0s0 FA c 1 is available after 2 gate delays. s 1 is available after 1 gate delay. c i y i x i c i y i x i x i c i y i s i c i1+ Sum Carry

23 Computing the add time (contd..) x0x0 y0y0 s2s2 FA x0x0 y0y0 x0x0 y0y0 s1s1 c2c2 s0s0 c1c1 c3c3 c0c0 x0x0 y0y0 s3s3 c4c4 Cascade of 4 Full Adders, or a 4-bit adder s 0 available after 1 gate delays, c 1 available after 2 gate delays. s 1 available after 3 gate delays, c 2 available after 4 gate delays. s 2 available after 5 gate delays, c 3 available after 6 gate delays. s 3 available after 7 gate delays, c 4 available after 8 gate delays. For an n -bit adder, s n-1 is available after 2n-1 gate delays c n is available after 2n gate delays.

24 Fast addition Recall the equations: Second equation can be written as: We can write: G i is called generate function and P i is called propagate function G i and P i are computed only from x i and y i and not c i, thus they can be computed in one gate delay after X and Y are applied to the inputs of an n -bit adder.

25 Carry lookahead All carries can be obtained 3 gate delays after X, Y and c 0 are applied. -One gate delay for P i and G i - Two gate delays in the AND-OR circuit for c i+1 All sums can be obtained 1 gate delay after the carries are computed. Independent of n, n -bit addition requires only 4 gate delays. This is called Carry Lookahead adder.

26 Carry-lookahead adder Carry-lookahead logic B cell s 3 P 3 G 3 c 3 P 2 G 2 c 2 s 2 G 1 c 1 P 1 s 1 G 0 c 0 P 0 s 0. c 4 x 1 y 1 x 3 y 3 x 2 y 2 x 0 y 0 G i c i... P i s i x i y i 4-bit carry-lookahead adder. B-cell for a single stage.

27 Carry lookahead adder (contd..)  Performing n -bit addition in 4 gate delays independent of n is good only theoretically because of fan-in constraints.  Last AND gate and OR gate require a fan-in of (n+1) for a n- bit adder.  For a 4-bit adder ( n=4 ) fan-in of 5 is required.  Practical limit for most gates.  In order to add operands longer than 4 bits, we can cascade 4-bit Carry-Lookahead adders. Cascade of Carry-Lookahead adders is called Blocked Carry-Lookahead adder. c i  1  G i  P i G i  1  P i P i  1 G i  2 ..  P i P i  1 P 1 G 0  P i P i  1...P 0 c0c0

28 Blocked Carry-Lookahead adder Carry-out from a 4-bit block can be given as: Rewrite this as: Subscript I denotes the blocked carry lookahead and identifies the block. Cascade 4 4 -bit adders, c 16 can be expressed as:

29 Blocked Carry-Lookahead adder (contd..) After x i, y i and c 0 are applied as inputs: - G i and P i for each stage are available after 1 gate delay. - P I is available after 2 and G I after 3 gate delays. - All carries are available after 5 gate delays. - c 16 is available after 5 gate delays. - s 15 which depends on c 12 is available after 8 (5+3)gate delays (Recall that for a 4-bit carry lookahead adder, the last sum bit is available 3 gate delays after all inputs are available)

30 Multiplication of unsigned numbers (13) Multiplicand M 1 1 (143) Product P (11) Multiplier Q Partial product (PP) #1 1 Partial product (PP) # Partial product (PP) # Partial product (PP) #  Product of 2 n -bit numbers is at most a 2n -bit number. We should expect to store a double-length result. Unsigned multiplication can be viewed as addition of shifted versions of the multiplicand.

31 Multiplication of unsigned numbers (contd..)  We added the partial products at end.  Alternative would be to add the partial products at each stage.  Rules to implement multiplication are:  If the i th bit of the multiplier is 1, shift the multiplicand and add the shifted multiplicand to the current value of the partial product.  Hand over the partial product to the next stage  Value of the partial product at the start stage is 0.

32 Multiplication of unsigned numbers (contd..) i th multiplier bit carry in carry out j th multiplicand bit i th multiplier bit Bit of incoming partial product (PPi) Bit of outgoing partial product (PP(i+1)) FA Typical multiplication cell

33 Combinatorial array multiplier Product is: p 7,p 6,..p 0 Multiplicand is shifted by displacing it through an array of adders. Combinatorial array multiplier

34 Combinatorial array multiplier (contd..)  Combinatorial array multipliers are:  Extremely inefficient.  Have a high gate count for multiplying numbers of practical size such as 32-bit or 64-bit numbers.  Perform only one function, namely, unsigned integer product.  Improve gate efficiency by using a mixture of combinatorial array techniques and sequential techniques requiring less combinational logic.

35 Sequential multiplication  Recall the rule for generating partial products:  If the ith bit of the multiplier is 1, add the appropriately shifted multiplicand to the current partial product.  Multiplicand has been shifted left when added to the partial product.  However, adding a left-shifted multiplicand to an unshifted partial product is equivalent to adding an unshifted multiplicand to a right-shifted partial product.

36 Sequential multiplication (contd..) Register A (initially 0) q n1- m n1- n-bit Multiplicand M Control sequencer Multiplier Q 0 C Shift right adder Add/Noadd control a n1- a 0 q 0 m 0 0 MUX Load Register A with 0. Registers are used to store multiplier and multiplicand. Each cycle repeat the following: steps: 1. If the LSB q 0 =1 : -Add the multiplicand to A. -Store carry-out in flip-flop C Else if q 0 = 0 -Do not add. 2. Shift the contents of register A and Q to the right, and discard q 0.

37 Sequential multiplication (contd..) Register A (initially 0) q n1- m n1- n-bit Multiplicand M Control sequencer Multiplier Q 0 C Shift right adder Add/Noadd control a n1- a 0 q 0 m 0 0 MUX Initial configuration Add M C First cycle Second cycle Third cycle Fourth cycle No add Shift Add Shift Add QA Product