Addition, Subtraction, Logic Operations and ALU Design

Slides:



Advertisements
Similar presentations
Arithmetic for Computers
Advertisements

L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
1 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
Fast Adders See: P&H Chapter 3.1-3, C Goals: serial to parallel conversion time vs. space tradeoffs design choices.
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.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
ECE 232 L8.Arithm.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 8 Computer.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 6 - Logic &
L9 – Arithmetic Circuits 1 Comp 411 – Fall /14/09 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
MIPS Architecture Arithmetic/Logic Instructions ALU Design – Chapter 4 By N. Guydosh 2/17/04.
Lecture 8 Arithmetic Logic Circuits
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Arithmetic-Logic Units CPSC 321 Computer Architecture Andreas Klappenecker.
ECE 301 – Digital Electronics
ECE 301 – Digital Electronics
Overview Iterative combinational circuits Binary adders
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 4 – Arithmetic Functions Logic and Computer.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Basic Arithmetic (adding and subtracting)
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter 6-1 ALU, Adder and Subtractor
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ć.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
Lecture 6: Multiply, Shift, and Divide
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
Computing Systems Designing a basic ALU.
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.
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.
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (
ECE 331 – Digital System Design Multi-bit Adder Circuits, Adder/Subtractor Circuit, and Multiplier Circuit (Lecture #12)
1  2004 Morgan Kaufmann Publishers Performance is specific to a particular program/s –Total execution time is a consistent summary of performance For.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
CPEN Digital System Design
1 Fundamentals of Computer Science Combinational Circuits.
Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University.
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.
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.
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
Computer Organization and Design Arithmetic & Logic Circuits Montek Singh Nov 2, 2015 Lecture 11.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
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.
Computer Arthmetic Chapter Four P&H.
CSCI206 - Computer Organization & Programming
MISP Assembly.
COMS 361 Computer Organization
Instructor: Mozafar Bag-Mohammadi University of Ilam
A 1-Bit Arithmetic Logic Unit
ECE 352 Digital System Fundamentals
COMS 361 Computer Organization
Presentation transcript:

Addition, Subtraction, Logic Operations and ALU Design Lecture 5 Addition, Subtraction, Logic Operations and ALU Design Professor Mike Schulte Computer Architecture ECE 201

Unsigned Binary Integers Unsigned binary numbers are typically used to represent computer addresses or other values that are guaranteed not to be negative. An n-bit unsigned binary integer A = an-1 an-2... a1 a0 has a value of What is 1011 as an unsigned integer? An n-bit unsigned binary integer has a range from 0 to 2n - 1. What is the value of of the 8-bit unsigned integer 10000001?

Signed Binary Integers Signed binary numbers are typically used to represent data that is either positive or negative. The most common representation for signed binary integers is the two's complement format. An n-bit 2’s comp binary integer A = an-1 an-2... a1 a0 has a value of What is 1011 as a 2’s comp. integer? An n-bit 2’s comp. binary integer has a range from - 2n-1 to 2n-1 - 1. What is the value of the 2’s comp. Integer 10000001? -

2’s Comp. Negatation To negate a two's complement integer, invert all the bits and add a one to the least significant bit. What are the two’s complements of 6 = 0110 -4 = 1100 Another way to negate is: Copy all bits to the right of the right-most ‘1’ Copy the right-most ‘1’ Invert all bits to the right-most ‘1’ Which way do you think is more commonly used by hardware? Why?

Questions What is the value of the two's complement integer 1111111111111101 in decimal? What is the value of the unsigned integer 1111111111111101 in decimal? What is the negation of the two's complement integer 1010000000000000 in binary?

Two’s Comp. Addition To add two's complement numbers, add the corresponding bits of both numbers with carry between bits. For example, 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 + 2 = 0010 +-2 = 1110 + 2 = 0010 + -2 = 1110 -------- --------- --------- --------- Unsigned and two’s complement addition are performed exactly the same way, but how they detect overflow differs.

Two’s Comp. Subtraction To subtract two's complement numbers we first negate the second number and then add the corresponding bits of both numbers. For example: 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 - 2 = 0010 - -2 = 1110 - 2 = 0010 - -2 = 1110 ---------- --------- --------- ---------

Overflow When adding or subtracting numbers, the sum or difference can go beyond the range of representable numbers. This is known as overflow. For example, for two's complement numbers, 5 = 0101 -5 = 1011 5 = 0101 -5 = 1011 + 6 = 0110 + -6 = 1010 - -6 = 1010 - +6 = 0110 -------- --------- --------- --------- -5 = 1011 5 = 0101 -5 = 1011 5 = 0101 Overflow creates an incorrect result that should be detected.

2’s Comp - Detecting Overflow When adding two's complement numbers, overflow will only occur if the numbers being added have the same sign the sign of the result is different If we perform the addition an-1 an-2 ... a1 a0 + bn-1bn-2… b1 b0 ---------------------------------- = sn-1sn-2… s1 s0 Overflow can be detected as Overflow can also be detected as where cn-1and cn are the carry in and carry out of the most significant bit.

Unsigned - Detecting Overflow For unsigned numbers, overflow occurs if there is carry out of the most significant bit. For example, 1001 = 9 +1000 = 8 =0001 = 1 With the MIPS architecture Overflow exceptions occur for two’s complement arithmetic add, sub, addi Overflow exceptions do not occur for unsigned arithmetic addu, subu, addiu

Shift Operations The MIPS architecture defines various shift operations: (a) sll r1, r2, 3 r2 = 10101100 (shfit left logical) r1 = 01100000 - shift in zeros to the least significant bits (b) srl r1, r2, 3 r2 = 10101100 (shift right logical) r1 = 00010101 - shift in zeros to the most significant bits (c) sra r1, r2, 3 r2 = 10101100 (shift right arithmetic) r1 = 11110101 - copy the sign bit to the most significant bits The are also versions of these instructions that take three register operands.

Logical Operations In the MIPS architecture logical operations (and, or, xor) correspond to bit-wise operations. (a) and r1, r2, r3 r3 = 1010 (r1 is 1 if r2 and r3 are both one) r2 = 0110 r1 = 0010 (a) or r1, r2, r3 r3 = 1010 (r1 is 1 if r2 or r3 is one) r1 = 1110 (a) xor r1, r2, r3 r3 = 1010 (r1 is 1 if r2 and r3 are different) r1 = 1100 Immediate versions of these instructions are also supported.

ALU Interface We will be designing a 32-bit ALU with the following interface. B A 32 32 Z 3 ALUop ALU V C32 ALUOp | Function 000 | AND 001 | OR 010 | ADD 110 | SUBTRACT 111 | SET-ON-LESS-THAN 32 Result Z =1, if Result=0 V= 1, if Overflow C32 = 1, if Carry-Out

Set-on-less-than The set-on-less instruction slt $s1, $s2, $s3 sets $s1 to ‘1’ if ($s2 < $s3) and to ‘0’ otherwise. This can be accomplished by subtacting $s2 from $s3 setting the least significant bit to the sign bit of the result setting all other bits to zero if overflow occurs the sign bit needs to be inverted For example, $s2 = 1010 $s2 = 0111 -$s3 = 1011 -$s3 = 0100 = 1111 = 0011 $s1 = 0001 $s1 = 0000

Full Adder A fundamental building block in the ALU is a full adder (FA). A FA performs a one bit addition. ai+ bi + ci = 2ci+1 + si bi ai ci+1 ci 1 1 1 0 ai 0 1 0 1 0 1 1 1 1 1 0 0 FA ci+1 ci bi si si

Full Adder Logic Equations si is ‘1’ if an odd number of inputs are ‘1’. ci+1 is ‘1’ if two or more inputs are ‘1’ . ai bi ci ci+1 si 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1

Full Adder Design One possible implementation of a full adder uses nine gates. 7

1-Bit ALU The full adder, an xor gate, and a 4-to-1 mux are combined to form a 1-bit ALU. 7 bi ai lessi 1-bit ALU ci ci+1 ALUop2:0 ri ALUOp | Function 000 | AND 001 | OR 010 | ADD 110 | SUBTRACT 111 | SET-ON-LESS-THAN 2 1 3

1-bit ALU for MSB The ALU for the MSB must also detect overflow and indicate the sign of the result. 7 2 1 3

Larger ALUs Three 1-bit ALUs, a 1-bit MSB ALU, and a 4-input NOR gate can be concatenated to form a 4-bit ALU. b3 a3 b2 a2 b1 a1 bo a0 c3 c2 c1 c0 =ALUop2 c4 1-bit MSB ALU 1-bit ALU 1-bit ALU 1-bit ALU V set ALUop2:0 r3 r2 r1 r0 Z 31 1-bit ALUs, a 1-bit MSB ALU, and a 32-input NOR gate can be concatenated to form a 32-bit ALU.

Gate Counts Assume How many gates are required by 4-input mux = 5 gates XOR gate = 3 gates AND/OR gate = 1 gate Inverter = 0.5 gates. How many gates are required by A 1-bit ALU? A 4-bit ALU? A 32-bit ALU? An n-bit ALU? Additional gates needed to compute V and Z 7 2 1 3

Gate Counts Assume How many gates are required by 4-input mux = 5 gates XOR gate = 3 gates AND/OR gate = 1 gate Inverter = 0.5 gates. How many gates are required by A 1-bit ALU? 16 A 4-bit ALU?16x4 A 32-bit ALU?16x32 An n-bit ALU?16xn (n-1) 2-input OR gates, 1 inverter and 1 XOR gate are needed to compute V and Z for an n-bit ALU 7 2 1 3

Gate Delays Assume delays of What is the delay of 4-input mux = 2t XOR gate = 2t AND/OR gate = 1t Inverter = 1t What is the delay of A 1-bit ALU? 10t A 4-bit ALU? A 32-bit ALU? An n-bit ALU? Additional delay needed to compute Z 7 2 1 3

Ripple Carry Adder (RCA) With the previous design the carry “rippled” from one 1-bit ALU to the next. b3 a3 b2 a2 b1 a1 bo a0 c4 c3 c2 c1 c0 1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU 13t 11t 9t 7t 16t 14t 12t 10t r3 r2 r1 r0 These leads to a relatively slow design. Z is ready at 19 t

Gate Delays Assume delays of What is the delay of 4-input mux = 2t XOR gate = 2t AND/OR gate = 1t Inverter = 1t What is the delay of A 1-bit ALU? 10t A 4-bit ALU? 16t A 32-bit ALU? (2x32+8)t = 72t An n-bit ALU? (2n+8)t log2(n) levels of 2-input OR gates and 1 inverter are needed to compute Z. 7 2 1 3

Carry Lookahead Adder (CLA) With a CLA, the carries are computed in parallel using carry lookahead logic (CLL). b3 a3 b2 a2 b1 a1 bo a0 c3 c2 c1 c0 1-bit ALU* 1-bit ALU* 1-bit ALU* 1-bit ALU* r3 p3 g3 r2 p2 g2 r1 p1 g1 r0 p0 g0 c4 Carry Lookahead Logic

Carry Logic Equation The carry logic equation is We define a propagate signal and a generate signal This allows the carry logic equation to be rewritten as

Carry Lookahead Logic For a 4-bit carry lookahead adder, the carries are computed as c1 = g0 + p0c0 c2 = g1 + p1c1= g1 + p1(g0 + p0c0) = g1 + p1g0 + p1p0c0 c3 = g2 + p2c2= g2 + p2(g1 + p1g0 + p1p0c0) = g2 + p2g1 + p2p1g0 + p2p1p0c0 c4 = g3 + p3c3= g3 + p3(g2 + p2g1 + p2p1g0 + p2p1p0c0) = g3 + p3g2 + p3p2g1 + p3p2p1g0 + p3p2p1p0c0 How many gates does the 4-bit CLL require, if gates can have unlimited fan-in? If each logic level has a delay of only 1t, the CLL has a delay of 2t. => In practice this may not be realistic.

Modifying the 1-bit ALU How would we modify our 1-bit ALU if it is to be used in a CLA? How many gates does the modified 1-bit ALU require? How many gates does a 4-bit CLA require? How many gate delays until pi and gi are ready? 7 2 1 3

4-bit CLA Timing With a carry lookahead adder, the carries are computed in parallel using carry lookahead logic. b3 a3 b2 a2 b1 a1 bo a0 c3 c2 c1 c0 1-bit ALU* 1-bit ALU* 1-bit ALU* 1-bit ALU* 5t 5t 10t 3t 3t r3 p3 g3 r2 p2 g2 r1 p1 g1 r0 p0 g0 c4 Carry Lookahead Logic 5t This design requires 15x4 +14 = 74 gates, without computing V or Z

16-bit ALU - Version 1 A 16-bit ALU could be constructed by concatenating four 4-bit CLAs and letting the carry “ripple” between 4-bit “blocks”. b15:12 a15:12 b11:8 a11:8 b7:4 a7:4 b3:0 a3:0 c16 c12 c8 c4 c0 4-bit CLA 4-bit CLA 4-bit CLA 4-bit CLA 11t 9t 7t 5t 16t 14t 12t 10t r15:12 r11:8 r7:4 r3:0 This design requires 74x4 = 296 gates, without computing V or Z.

16-bit ALU - Version 2 Another approach is to use a second level of carry lookahead logic. This approach is faster, but requires more gates 16 x15 + 5 x 14 =310 gates b15:12 a15:12 b11:8 a11:8 b7:4 a7:4 b3:0 a3:0 c12 c8 c4 c0 4-bit CLA* 4-bit CLA* 4-bit CLA* 4-bit CLA* 7t 7t 14t 5t 5t r15:12 r11:8 r7:4 r3:0 Carry Lookahead Logic c16

4-bit CLA* The 4-bit CLA* (Block CLA) is similar to the first 4-bit CLA, except the CLL computes a “block” generate and “block propagate”, instead of a carry out. Thus the computation c4 = g3 + p3g2 + p3p2g1 + p3p2p1g0 + p3p2p1p0c0 is replaced by P3:0 = p3p2p1p0 G3:0 = g3 + p3g2 + p3p2g1 + p3p2p1g0 Note: c4 = G3:0 + P3:0c0 This approach limits the maximum fan-in to four, and the carry-lookahead logic still requires 14 gates.

Conclusions An n-bit ALU can be designed by concatenating n 1-bit ALUs. Carry lookahead logic can be used to improve the speed of the computation. A variety of design options exist for implementing the ALU. The best design depends on area, delay, and power requirements, which vary based on the underlying technology.