CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.

Slides:



Advertisements
Similar presentations
ADDER, HALF ADDER & FULL ADDER
Advertisements

EET 1131 Unit 7 Arithmetic Operations and Circuits
Datorteknik ArithmeticCircuits bild 1 Computer arithmetic Somet things you should know about digital arithmetic: Principles Architecture Design.
Cosc 2150: Computer Organization Chapter 3: Boolean Algebra and Digital Logic.
1 Foundations of Software Design Lecture 3: How Computers Work Marti Hearst Fall 2002.
Fall 2005 L15: Combinational Circuits Lecture 15: Combinational Circuits Complete logic functions Some combinational logic functions –Half adders –Adders.
Fall 2007 L15: Combinational Circuits Lecture 15: Combinational Circuits Complete logic functions Some combinational logic functions –Half adders –Adders.
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)
ECE 301 – Digital Electronics
Chapter 5 Arithmetic Logic Functions. Page 2 This Chapter..  We will be looking at multi-valued arithmetic and logic functions  Bitwise AND, OR, EXOR,
Part 2: DESIGN CIRCUIT. LOGIC CIRCUIT DESIGN x y z F F = x + y’z x y z F Truth Table Boolean Function.
Building Adders & Sub tractors Dr Ahmed Telba. Introducing adder circuits Adder circuits are essential inside microprocessors as part of the ALU, or arithmetic.
CS231: Computer Architecture I Laxmikant Kale Fall 2004.
Computer Arithmetic Nizamettin AYDIN
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
Logical Circuit Design Week 8: Arithmetic Circuits Mentor Hamiti, MSc Office ,
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Basic Arithmetic (adding and subtracting)
CS1Q Computer Systems Lecture 8
Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU.
Fall 2004EE 3563 Digital Systems Design EE 3563 Comparators  Comparators determine if two binary inputs are equal  Some will signal greater than/less.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
Basic Arithmetic (adding and subtracting)
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
Digital Electronics and Computer Interfacing
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
Arithmetic Logic Unit (ALU) Anna Kurek CS 147 Spring 2008.
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow.
Combinational Circuits
IT253: Computer Organization
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
CS1Q Computer Systems Lecture 8
CHAPTER 2 Digital Combinational Logic/Arithmetic Circuits
CO5023 Introduction to Digital Circuits. What do we know so far? How to represent numbers (integers and floating point) in binary How to convert between.
1 Fundamentals of Computer Science Combinational Circuits.
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.
Number Representation (Part 2) Computer Architecture (Fall 2006)
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.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
1 The ALU l ALU includes combinational logic. –Combinational logic  a change in inputs directly causes a change in output, after a characteristic delay.
Explain Half Adder and Full Adder with Truth Table.
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
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.
CS231: Computer Architecture I Laxmikant Kale Fall 2002.
Combinational Circuits
Somet things you should know about digital arithmetic:
Addition and multiplication
Fundamentals & Ethics of Information Systems IS 201
Summary Half-Adder Basic rules of binary addition are performed by a half adder, which has two binary inputs (A and B) and two binary outputs (Carry out.
MIPS ALU.
ECE 331 – Digital System Design
CSE Winter 2001 – Arithmetic Unit - 1
Arithmetic Circuits (Part I) Randy H
Week 7: Gates and Circuits: PART II
Lecture 11: Hardware for Arithmetic
COMS 361 Computer Organization
Addition and multiplication
Addition and multiplication
ECE 352 Digital System Fundamentals
Combinational Circuits
ECE 352 Digital System Fundamentals
ECE 352 Digital System Fundamentals
Presentation transcript:

CS1Q Computer Systems Lecture 9 Simon Gay

Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore we need circuits for arithmetic operations. Naturally, numbers will be represented in binary. We’ll start with addition. Recall that addition in binary is just like addition in decimal: carry in 1 carry out typical column Each column: add three bits (two from the original numbers, one carry input) and produce two bits (sum and carry output).

Lecture 9CS1Q Computer Systems - Simon Gay3 Designing an Adder Here is the truth table for the single bit addition function. The bits being added are x and y. The carry input is Cin. The sum is s and the carry output is Cout. yxCinCouts Notice that the Cout and s columns, interpreted as a 2 bit binary number, are simply the sum of the x, y and Cin columns. It turns out that Cout is the majority voting function from Lecture 5, and s is the parity function from Lecture 6.

Lecture 9CS1Q Computer Systems - Simon Gay4 Implementing the Adder We now know that so we can construct a circuit: A single bit adder is usually represented like this:

Lecture 9CS1Q Computer Systems - Simon Gay5 Multi-Bit Addition Addition of multi-bit numbers is achieved by chaining single bit adders together. Here is a 4 bit adder. The inputs are x3 x2 x1 x0 and y3 y2 y1 y0. The output is s4 s3 s2 s1 s0 (a 5 bit number). The carry out from each adder is fed into the carry in of the next adder. The carry in of the adder for the least significant bit is set to 0. Note that the sum of two n bit numbers can always be expressed in n+1 bits: if and then

Lecture 9CS1Q Computer Systems - Simon Gay6 Half Adders In effect we have directly implemented addition of three binary digits. Let’s consider addition of just two digits, which is obviously more fundamental, even though it does not directly correspond to the original calculation. Adding two bits x and y produces a sum s and a carry c: xysc We can immediately see that

Lecture 9CS1Q Computer Systems - Simon Gay7 Half Adders xysc The half adder consists of an AND gate and an XOR gate:

Lecture 9CS1Q Computer Systems - Simon Gay8 Two Halves Make a Whole The following circuit uses two half adders to implement a full adder. Exercise: use a truth table to check that this circuit is correct.

Lecture 9CS1Q Computer Systems - Simon Gay9 Ripple Carry The electronic implementations of logic gates do not work instantaneously: when the inputs change there is a short delay, perhaps a few picoseconds, before the outputs change. In our multi-bit adder, these delays accumulate because the carry bits have to propagate all the way along the circuit. This adder design is called ripple carry. The more bits, the longer the delay. Ripple carry delays would be very significant in a fast CPU. More sophisticated adder designs exist, which use various shortcuts to calculate carry bits without propagating them along the whole word. For more details, consult the books.

Lecture 9CS1Q Computer Systems - Simon Gay10 Subtraction To calculate x - y we calculate x + (-y) where -y is calculated in the 2s complement representation by inverting all the bits of y and then adding 1. A modification of the addition circuit does the trick: NOT gates do the inversion, and the 1 can easily be added by connecting the rightmost carry input to 1 instead of 0. The final carry output is ignored so that we get a 4 bit result. When working with 2s complement numbers, the final carry does not allow a 5 bit result to be produced.

Lecture 9CS1Q Computer Systems - Simon Gay11 An Add/Subtract Unit We can construct a circuit which either adds or subtracts, under the control of an input signal. A 2-1 multiplexer is used to select either plain or inverted values of the second input. ADD not x y control output MUX 1 0 Cin 32 1 for subtract, 0 for add control signal also gives correct Cin data of any width

Lecture 9CS1Q Computer Systems - Simon Gay12 A Simple ALU Using similar ideas, here is an ALU with 4 functions: add, subtract, AND, OR. ADD/SUB AND OR MUX xy output c1c0 c1 c0 0 0 add 0 1 sub 1 0 AND 1 1 OR

Lecture 9CS1Q Computer Systems - Simon Gay13 Other Mathematical Operations There is a sequence of mathematical operations of increasing complexity: addition/subtraction multiplication division square root transcendental functions (log, sin, cos, …) … Where is the hardware/software boundary?

Lecture 9CS1Q Computer Systems - Simon Gay14 Other Mathematical Operations We have seen that integer addition and subtraction are easy to implement in hardware. We have also seen that integer multiplication is easy to implement in software (e.g. in assembly language for the IT Machine). More complex mathematical operations can be implemented by more complex software. For simple CPUs (e.g. microprocessors of the late 1970s/early 1980s, such as the 6502 or Z80) this is a natural place for the hardware/software boundary. Modern microprocessors are more complex (e.g. Pentium 4 computes transcendental functions for 128 bit floating point in hardware).

Lecture 9CS1Q Computer Systems - Simon Gay15 Multiplication We can design a circuit for integer multiplication. If we multiply two 4 bit numbers x = x x x x and y y y y then the result is an 8 bit number z z z z z z z z. x  y y y y = x  (y  8 + y  4 + y  2 + y ) = x  y  8 + x  y  4 + x  y  2 + x  y = (x  y )  8 + (x  y )  4 + (x  y )  2 + x  y x  y zzzzzzzz

Lecture 9CS1Q Computer Systems - Simon Gay16 Multiplication AND x x y + AND y 0 + y + y carry in = 0 carry out z z z z zzzz 3210 x x

Lecture 9CS1Q Computer Systems - Simon Gay17 Multiplication Any calculation which can be done in a fixed number of steps can be converted into a circuit in a similar way. Such a circuit is faster than a software solution (but not instant). But the circuit may be large: for multiplication, the size of the circuit is proportional to the square of the word length. Key point: there’s a trade-off between execution time, and space (area on the CPU chip). With older manufacturing technologies, space was at a premium, therefore hardware operations stopped at addition. Nowadays, time is more significant. In practice, a circuit for a complex operation such as division is more likely to be designed as a state machine - more details later.