Csci136 Computer Architecture II Lab#5 Arithmetic Review ALU Design Ripple Carry Adder & Carry lookahead HW #4: Due on Feb 22, before class Feb.16, 2005.

Slides:



Advertisements
Similar presentations
Arithmetic for Computers
Advertisements

Lecture 19: Hardware for Arithmetic Today’s topic –Designing an ALU –Carry Look-Ahead Adder 1.
1 Lecture 12: Hardware for Arithmetic Today’s topics:  Designing an ALU  Carry-lookahead adder Reminder: Assignment 5 will be posted in a couple of days.
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.
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris.
Arithmetic II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
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.
Chap 3.3~3.5 Construction an Arithmetic Logic Unit (ALU) Jen-Chang Liu, Spring 2006.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Arithmetic-Logic Units CPSC 321 Computer Architecture Andreas Klappenecker.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
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.
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.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
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)
Chapter 6-1 ALU, Adder and Subtractor
Number Systems and Arithmetic or Computers go to elementary school Reading – Peer Instruction Lecture Materials for Computer Architecture by Dr.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Basic Arithmetic (adding and subtracting)
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
CSCI 136 Lab 1: 135 Review.
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.
Arithmetic Logic Unit (ALU) Anna Kurek CS 147 Spring 2008.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
Lecture 18: Hardware for Arithmetic Today’s topic –Intro to Boolean functions (Continued) –Designing an ALU 1.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (
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.
1  2004 Morgan Kaufmann Publishers Lets Build a Processor Almost ready to move into chapter 5 and start building a processor First, let’s review Boolean.
Addition, Subtraction, Logic Operations and ALU Design
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.
Gates AND, OR, NOT NAND, NOR Combinational logic No memory A set of inputs uniquely and unambiguously specifies.
1 Lecture 11: Hardware for Arithmetic Today’s topics:  Logic for common operations  Designing an ALU  Carry-lookahead adder.
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.
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.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Computer Arthmetic Chapter Four P&H.
Lecture 11: Hardware for Arithmetic
Integer Multiplication and Division
CSCI206 - Computer Organization & Programming
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
MISP Assembly.
CSCI206 - Computer Organization & Programming
Lecture 11: Hardware for Arithmetic
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
COMS 361 Computer Organization
A 1-Bit Arithmetic Logic Unit
MIPS Assembly.
MIPS assembly.
MIPS instructions.
Presentation transcript:

Csci136 Computer Architecture II Lab#5 Arithmetic Review ALU Design Ripple Carry Adder & Carry lookahead HW #4: Due on Feb 22, before class Feb.16, 2005

Signed and Unsigned Numbers Conversion to Decimal Num’s d n,d n-1,…,d 0  d n *base n +d n-1 *base n-1 +…+d 0 *base 0 Example:  0xABCD  10* * * *16 0 =  1101  1*2 3 +1*2 2 +0*2 1 +1*1 0 = 13

Signed and Unsigned Numbers Signed versus unsigned comparison  Assume 8-bit words $s0: two $s1: two slt $t0, $s0, $s1#signed comparison sltu $t0, $s0, $s1#unsigned comparison

Signed and Unsigned Numbers Sign Extension  16-bit to 32-bit: 12 ten, -12 ten  When? when you shift a register right … the sign bit is repeated to keep a negative number negative  Arithmetic Shift If the sign bit isn’t extended.. (i.e. empty spots filled with 0 s) then the shift is called “Logical” variety of shift

Sign Extension Assume 8 bit words… Shift right logical -11 by 2?  srl Shift right arithmetic -11 by 2?  sra Shift left logical -11 by 2?  sll

Useful Shifts Considering an 8 bit word… how would we compute dividing -6 by 2? Consider an 8 bit word… how would we compute multiplying -7 by 4?

Useful Shifts Shifts are fast. Compilers will often substitute shifts for multiplication and division of integers by powers of 2. Fast multiplication: int fmult(int a,b) { if(b == 0) { return 0; } if (even(b)) return fmult(2*a,b/2); if (odd(b)) return (a+fmult(a, b-1)); }

Addition and Subtraction Sub: a – b = a + (-b)  -b ten = invert(b) + 1 To get negative number from a positive.. Invert all digits and add 1. To get a positive number from a negative… Invert all digits and add 1.

What is Overflow? Consider unsigned 8 bit integers.. What happens when we add 0x73 and 0xA9 ? Can we get overflow when we add a positive and a negative number? Consider signed 8 bit (2’s complement) integers.. what happens when we add 0xBC and 0xB0?

Overflow Conditions for Addition and Subtraction OpABResult indicating overflow A+B>=0 <0 A+B<0 >=0 A-B>=0<0 A-B<0>=0

ALU Design Truth Tables  One logic function that is used for a variety of purposes (including within adders and to compute parity) is exclusive OR. The output of a two-input exclusive OR function is true only if exactly one of the inputs is true. Show the truth table for a two-input exclusive OR function and implement this function using AND gates, OR gates, and inverters.

ALU Design Building Logic Gates  Prove that the NOR gate is universal by showing how to build the AND, OR, and NOT functions using a two-input NOR gate.  Prove that the NAND gate is universal by showing how to build the AND, OR, and NOT functions using a two-input NAND gate.

Ripple Carry Adder CarryOut = b ∙ CarryIn + a ∙ CarryIn + a ∙ b

Faster Addition: Carry Lookahead Objective  Speed up the computation  Simplify the hardware 1st-level of Abstraction  Motivation: c i = f (a, b, c i-1 )  c i = f (a, b, c 0 ) c 1 = (a 0 +b 0 )∙c 0 + a 0 ∙b 0 c 2 = (a 1 +b 1 )∙c 1 + a 1 ∙b 1 = (a 1 +b 1 )∙((a 0 +b 0 )∙c 0 + a 0 ∙b 0 ) + a 1 ∙b 1 c 3 = (a 2 +b 2 )∙c 2 + a 2 ∙b 2 = (a 2 +b 2 )∙((a 1 +b 1 )∙((a 0 +b 0 )∙c 0 + a 0 ∙b 0 ) + a 1 ∙b 1 ) + a 2 ∙b 2 ∙∙∙∙∙  Simplify: g i = a i ∙b i, p i = a i + b i c i = g i-1 + g i-2 ∙p i-1 + … + g 0 ∙p i-1 ∙p i-2 ∙…∙p 1 + c 0 ∙p i-1 ∙…∙p 0

Faster Addition: Carry Lookahead 2nd-level of Abstraction  Motivation: 1st-level abstraction is still expensive! c 8 = g 7 + g 6 ∙p 7 + g 5 ∙p 7 ∙p 6 + g 4 ∙p 7 ∙p 6 ∙p 5 + g 3 ∙p 7 ∙p 6 ∙p 5 ∙p 4 + g 2 ∙p 7 ∙p 6 ∙p 5 ∙p 4 ∙p 3 + g 1 ∙p 7 ∙p 6 ∙p 5 ∙p 4 ∙p 3 ∙p 2 ∙p 1 + c 0 ∙p 7 ∙p 6 ∙p 5 ∙p 4 ∙p 3 ∙p 2 ∙p 1 ∙p 0  How: Divide the bits into groups(sizeof n), each group using the carry-lookahead logic Connect them in ripple carry way

Faster Addition: Carry Lookahead c 8 = G 7,4 + G 3,0 ∙P 7,4 + c 0 ∙P 7,4 ∙P 3,1

HW#4 Give MIPS code for abs $t2, $t3 If a>=0 then abs(a)=a else abs(a)=-a end

HW#4 Load 32-bit address lui $t0, A_upper_adjusted lw $s0, A_lower($t0)  A_lower will be sign-extended to compute the address! e.g. A=0x0001A001 ? + 0xFFFFA001 = 0x0001A001

HW#4 Carry out bit?  Overflow conditions for addition and subtraction OpABResult indicating overflow A+B>=0 <0 A+B<0 >=0 A-B>=0<0 A-B<0>=0

HW#4 slt $t0, $s0, $s1  slt: R[rd] = (R[rs]<R[rt])? 1:0  Compare? bne, beq

HW#4 Relative Performance of Adders  Equal time for AND, OR operation  Ripple carry: c1  c2  c3  c4 Time: add them together!  Carry lookahead: {p1, p2, p3, p4, g1, g2, g3, g4}  {c1, c2, c3, c4} Time?