Addition and multiplication

Similar documents
Arithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit

Chapter 4. Combinational Logic

Chapter 3 Arithmetic for Computers

Binary Arithmetic. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T.

Combinational Circuits

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 3 DLD P VIDYA SAGAR

Arithmetic-logic units

Binary Adders: Half Adders and Full Adders

CS/COE 0447 Example Problems for Exam 2 Spring 2011

ECE 341. Lecture # 6

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

DIGITAL TECHNICS. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute

COMBINATIONAL LOGIC CIRCUITS

Basic Arithmetic (adding and subtracting)

Tailoring the 32-Bit ALU to MIPS

ECE 341 Midterm Exam

ECE331: Hardware Organization and Design

Computer Architecture Set Four. Arithmetic

Arithmetic Logic Unit. Digital Computer Design

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

Arithmetic and Logical Operations

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Chapter 3 Part 2 Combinational Logic Design

Number Systems and Computer Arithmetic

Chapter 6 Combinational-Circuit Building Blocks

EE 8351 Digital Logic Circuits Ms.J.Jayaudhaya, ASP/EEE

CO Computer Architecture and Programming Languages CAPL. Lecture 9

CS/COE 0447 Example Problems for Exam 2 Fall 2010

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-II COMBINATIONAL CIRCUITS

Chapter 4 Arithmetic Functions

Chapter Three. Digital Components

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Combinational Logic. Prof. Wangrok Oh. Dept. of Information Communications Eng. Chungnam National University. Prof. Wangrok Oh(CNU) 1 / 93

Let s put together a Manual Processor

CPE300: Digital System Architecture and Design

Arithmetic Operations

Experiment 7 Arithmetic Circuits Design and Implementation

Combinational Logic II

LOGIC CIRCUITS. Kirti P_Didital Design 1

Microcomputers. Outline. Number Systems and Digital Logic Review

D I G I T A L C I R C U I T S E E

*Instruction Matters: Purdue Academic Course Transformation. Introduction to Digital System Design. Module 4 Arithmetic and Computer Logic Circuits

Chapter 3: part 3 Binary Subtraction

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Department of Electrical and Computer Engineering University of Wisconsin - Madison. ECE/CS 352 Digital System Fundamentals.

CS 5803 Introduction to High Performance Computer Architecture: Arithmetic Logic Unit. A.R. Hurson 323 CS Building, Missouri S&T

ALU Design. 1-bit Full Adder 4-bit Arithmetic circuits. Arithmetic and Logic Unit Flags. Add/Subtract/Increament/Decrement Circuit

Two-Level CLA for 4-bit Adder. Two-Level CLA for 4-bit Adder. Two-Level CLA for 16-bit Adder. A Closer Look at CLA Delay

1. Mark the correct statement(s)

carry in carry 1101 carry carry

Arithmetic Circuits. Design of Digital Circuits 2014 Srdjan Capkun Frank K. Gürkaynak.

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

ECE 30 Introduction to Computer Engineering

Control Unit: Binary Multiplier. Arturo Díaz-Pérez Departamento de Computación Laboratorio de Tecnologías de Información CINVESTAV-IPN

Learning Outcomes. Spiral 2 2. Digital System Design DATAPATH COMPONENTS

Korea University of Technology and Education

IA Digital Electronics - Supervision I

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District DEPARTMENT OF INFORMATION TECHNOLOGY CS 2202 DIGITAL PRINCIPLES AND SYSTEM DESIGN

By, Ajinkya Karande Adarsh Yoga

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Chapter 3 Part 2 Combinational Logic Design

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012

COMP 303 Computer Architecture Lecture 6

Binary Arithmetic Intro to Assembly Language CS 64: Computer Organization and Design Logic Lecture #3

Combinational Logic Use the Boolean Algebra and the minimization techniques to design useful circuits No feedback, no memory Just n inputs, m outputs

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Introduction to Digital Logic Missouri S&T University CPE 2210 Multipliers/Dividers

Timing for Ripple Carry Adder


Digital Logic & Computer Design CS Professor Dan Moldovan Spring 2010

Chapter 4. Combinational Logic. Dr. Abu-Arqoub

Combinational Logic Circuits

COMPUTER ARCHITECTURE AND ORGANIZATION Register Transfer and Micro-operations 1. Introduction A digital system is an interconnection of digital

Principles of Computer Architecture. Chapter 3: Arithmetic

Arithmetic Logic Unit (ALU)

Lecture 21: Combinational Circuits. Integrated Circuits. Integrated Circuits, cont. Integrated Circuits Combinational Circuits

Chapter 5. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 5 <1>

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Learning Outcomes. Spiral 2-2. Digital System Design DATAPATH COMPONENTS

LECTURE 4. Logic Design

At the ith stage: Input: ci is the carry-in Output: si is the sum ci+1 carry-out to (i+1)st state

Boolean Unit (The obvious way)

Learning Outcomes. Spiral 2 2. Digital System Design DATAPATH COMPONENTS

UNIT IV: DATA PATH DESIGN

BINARY SYSTEM. Binary system is used in digital systems because it is:

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

T insn-mem T regfile T ALU T data-mem T regfile

EC2303-COMPUTER ARCHITECTURE AND ORGANIZATION

Computer Architecture and Organization

Binary Multiplication

Software and Hardware

Outline. Introduction to Structured VLSI Design. Signed and Unsigned Integers. 8 bit Signed/Unsigned Integers

R10. II B. Tech I Semester, Supplementary Examinations, May

CHW 261: Logic Design

Integer Encoding and Manipulation

Transcription:

Addition and multiplication 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 focus on addition, subtraction, multiplication and arithmetic-logic units or ALUs, which are the heart of CPUs. Arithmetic hardware is an excellent example of many issues that we ve discussed, such as Boolean algebra, circuit analysis, data representation, and hierarchical, modular design. June 3, 23 2-23 Howard Huang

Binary addition by hand You can add two binary numbers one column at a time starting from the right, just like you add two decimal numbers. But remember it s binary. For example, + = and you have to carry! The initial carry in is implicitly Carry in Augend + Addend Sum most significant bit (MSB) least significant bit (LSB) June 3, 23 Addition and multiplication 2

Adding two bits We ll make a hardware adder based on our human addition algorithm. We start with a half adder, which adds two bits X and Y and produces a two-bit result: a sum S (the right bit) and a carry out C (the left bit). Here are truth tables, equations, circuit and block symbol. X Y C S C = XY S = X Y + XY = X Y Be careful! Now we use + for both arithmetic addition and the logical OR operation. June 3, 23 Addition and multiplication 3

June 3, 23 Addition and multiplication 4 Adding three bits + But what we really need to do is add three bits: the augend and addend bits, and the carry in from the right. A full adder circuit takes three inputs X, Y and C in, and produces a two-bit output consisting of a sum S and a carry out C out. This truth table should look familiar, as it was an example in the decoder and multiplexer lectures. S C out C in Y X

Full adder equations Using Boolean algebra, we can simplify S and C out as shown here. X Y C in C out S S = Σm(,2,4,7) = X Y C in + X YC in + XY C in + XYC in = X (Y C in + YC in ) + X(Y C in + YC in ) = X (Y C in ) + X(Y C in ) = X Y C in C out = Σm(3,5,6,7) = X YC in + XY C in + XYC in + XYC in = (X Y + XY )C in + XY(C in + C in ) = (X Y)C in + XY Notice that XOR operations simplify things a bit, but we had to resort to using algebra since it s hard to find XOR-based expressions with K-maps. June 3, 23 Addition and multiplication 5

Full adder circuit We write the equations this way to highlight the hierarchical nature of adder circuits you can build a full adder by combining two half adders! S = X Y C in C out = (X Y) C in + XY June 3, 23 Addition and multiplication 6

A four-bit adder Similarly, we can cascade four full adders to build a four-bit adder. The inputs are two four-bit numbers (A3A2AA and B3B2BB) and a carry in CI. The two outputs are a four-bit sum S3S2SS and the carry out CO. If you designed this adder without taking advantage of the hierarchical structure, you d end up with a 52-row truth table with five outputs! June 3, 23 Addition and multiplication 7

An example of 4-bit addition Let s put our initial example into this circuit, with A= and B=.. Fill in all the inputs, including CI= 2. The circuit produces C and S ( + + = ) 3. Use C to find C2 and S ( + + = ) 4. Use C2 to compute C3 and S2 ( + + = ) 5. Use C3 to compute CO and S3 ( + + = ) Woohoo! The final answer is. June 3, 23 Addition and multiplication 8

Overflow This particular example illustrates a case of overflow. The answer is five bits long, but the inputs and were each only four bits wide. Although the five-bit answer is correct, we cannot use it in any subsequent computations with this four-bit adder. For unsigned addition, overflow occurs when the carry out is. Overflows can never be prevented because computer hardware is finite. Even though we can make adders of arbitrary sizes, there will always be another number that won t fit. June 3, 23 Addition and multiplication 9

Ariane 5 In 996, the European Space Agency s Ariane 5 rocket was launched for the first time... and it exploded 4 seconds after liftoff. It turns out the Ariane 5 used software designed for the older Ariane 4. The Ariane 4 stored its horizontal velocity as a 6-bit signed integer. But the Ariane 5 reaches a much higher velocity, which caused an overflow in the 6-bit quantity. The overflow error was never caught, so incorrect instructions were sent to the rocket boosters and main engine. June 3, 23 Addition and multiplication

Hierarchical adder design When you add two 4-bit numbers the carry in is always, so why does the four-bit adder have a CI input? We can use CI to combine four-bit adders together to make even larger adders, just like we combined half adders and full adders earlier. Here is one way to build an eight-bit adder, for example. CI is also useful for subtraction, as we ll see next time. June 3, 23 Addition and multiplication

Ripple carry delays The diagram below shows our four-bit adder completely drawn out. This is called a ripple carry adder, because the inputs A, B and CI ripple leftwards until CO and S3 are produced. Ripple carry adders are slow! There is a very long path from A, B and CI to CO and S3. For an n-bit ripple carry adder, the longest path has 2n+ gates. The longest path in a 64-bit adder would include 29 gates! 9 8 7 6 5 4 3 2 June 3, 23 Addition and multiplication 2

A faster way to compute carry outs Instead of waiting for the carry out from each previous stage, we can minimize the delay by computing it directly with a two-level circuit. First we ll define two functions. The generate function G i produces when there must be a carry out from position i (i.e., when A i and B i are both ). G i P i G i = A i B i The propagate function P i is true when an incoming carry is propagated (i.e, when A i = or B i =, but not both). P i = A i B i Then we can rewrite the carry out function. C i+ = G i + P i C i A i B i C i C i+ June 3, 23 Addition and multiplication 3

Algebraic carry out hocus-pocus Let s look at the carry out equations for specific bits, using the general equation from the previous page C i+ = G i + P i C i. C = G + P C Ready to see the circuit? C 2 = G + P C = G + P (G + P C ) = G + P G + P P C C 3 = G 2 + P 2 C 2 = G 2 + P 2 (G + P G + P P C ) = G 2 + P 2 G + P 2 P G + P 2 P P C C 4 = G 3 + P 3 C 3 = G 3 + P 3 (G 2 + P 2 G + P 2 P G + P 2 P P C ) = G 3 + P 3 G 2 + P 3 P 2 G + P 3 P 2 P G + P 3 P 2 P P C These expressions are all sums of products, so we can use them to make a circuit with only a two-level delay. June 3, 23 Addition and multiplication 4

A faster four-bit adder June 3, 23 Addition and multiplication 5

Carry lookahead adders This is called a carry lookahead adder. By adding more hardware, we reduced the number of levels in the circuit and sped things up. We can combine carry lookahead adders just like ripple carry adders, and we can do carry lookahead between the adders too. How much faster is this? For a four-bit adder, not much. There are 4 gates in the longest path of a carry lookahead adder, versus 9 gates for a ripple carry adder. If we do the cascading properly, a 6-bit carry lookahead adder will have only 8 gates in the longest path, as opposed to 33 with a ripple carry adder. The newest processors use 64-bit adders. That s 2 vs. 29 gates! The delay of a carry lookahead adder grows logarithmically with the size of the adder, while a ripple carry adder s delay grows linearly. June 3, 23 Addition and multiplication 6

June 3, 23 Addition and multiplication 7 Binary multiplication by hand Multiplication can t be that hard! It s just repeated addition, so if we have adders, we should be able to do multiplication also. Here s an example of binary multiplication to get the mojo flowing. +

Binary multiplication Multiplicand Multiplier Partial products + Product Since we always multiply by either or, the partial products are always either or the multiplicand ( in this example). There are four partial products which are added to form the result. We can add them in pairs, using three adders. The product can have up to 8 bits, but we can use four-bit adders if we stagger them leftwards, like the partial products themselves. June 3, 23 Addition and multiplication 8

2 2 binary multiplication Here is an outline of multiplying the two-bit numbers AA and BB, to produce the four-bit product P3-P. B B A A AB AB + AB AB P3 P2 P P The bits of each partial product are computed A B A B A B by multiplying two bits of the input. Since two-bit multiplication is the same as the logical AND operation, we can use AND gates to generate the partial products. June 3, 23 Addition and multiplication 9

Here is a circuit that multiplies the two-bit numbers AA and BB, resulting in the four-bit product P3-P. For a 2 2 multiplier we can just use two half adders to sum the partial products. In general, though, we ll need full adders. The diagram on the next page shows how this can be extended to a four-bit multiplier, taking inputs A3-A and B3-B and outputting the product P7-P. A 2 2 binary multiplier June 3, 23 Addition and multiplication 2

A 4 4 binary multiplier June 3, 23 Addition and multiplication 2

Complexity of multiplication circuits In general, when multiplying an m-bit number by an n-bit number: There will be n partial products, one for each bit of the multiplier. This requires n- adders, each of which can add m bits. The circuit for 32-bit or 64-bit multiplication would be huge! June 3, 23 Addition and multiplication 22

Shifty arithmetic operations In decimal, an easy way to multiply by is to shift all the digits to the left, and tack a to the right end. 28 = 28 We can do a similar thing in binary. Shifting left once multiplies by two. = (in decimal, 3 2 = 6) Shifting left twice is equivalent to multiplying by four. = (in decimal, 3 4 = 2) Similarly, shifting once to the right is equivalent to dividing by two. = (in decimal, 2 2 = 6) June 3, 23 Addition and multiplication 23

Addition and multiplication summary Adder and multiplier circuits reflect human algorithms for addition and multiplication. Adders and multipliers are built hierarchically. We start with half adders and full adders and work our way up. Building these circuits from scratch using truth tables and K-maps would be pretty difficult. Adder circuits are limited in the number of bits that can be handled. An overflow occurs when a result exceeds this limit. There is a tradeoff between simple but slow ripple carry adders and more complex but faster carry lookahead adders. Multiplying and dividing by powers of two can be done with simple shifts. June 3, 23 Addition and multiplication 24