We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byTania Foxworthy
Modified about 1 year ago
.1 1999©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan http://www.cs.ucr.edu/~bhuyan/cs161/index.html
.2 1999©UCB °Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers °Binary numbers (base 2) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001... decimal: 0...2 n -1 °Of course it gets more complicated: numbers are finite (overflow) fractions and real numbers negative numbers e.g., no MIPS subi instruction; addi can add a negative number °How do we represent negative numbers? i.e., which bit patterns will represent which numbers? Numbers
.3 1999©UCB ° Sign Magnitude: One's Complement Two's Complement 000 = +0000 = +0000 = +0 001 = +1001 = +1001 = +1 010 = +2010 = +2010 = +2 011 = +3011 = +3011 = +3 100 = -0100 = -3100 = -4 101 = -1101 = -2101 = -3 110 = -2110 = -1110 = -2 111 = -3111 = -0111 = -1 °Issues: balance, number of zeros, ease of operations °Which one is best? Why? Possible Representations
.4 1999©UCB °32 bit signed numbers: 0000 0000 0000 0000 0000 0000 0000 0000 two = 0 ten 0000 0000 0000 0000 0000 0000 0000 0001 two = + 1 ten 0000 0000 0000 0000 0000 0000 0000 0010 two = + 2 ten... 0111 1111 1111 1111 1111 1111 1111 1110 two = + 2,147,483,646 ten 0111 1111 1111 1111 1111 1111 1111 1111 two = + 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0000 two = – 2,147,483,648 ten 1000 0000 0000 0000 0000 0000 0000 0001 two = – 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0010 two = – 2,147,483,646 ten... 1111 1111 1111 1111 1111 1111 1111 1101 two = – 3 ten 1111 1111 1111 1111 1111 1111 1111 1110 two = – 2 ten 1111 1111 1111 1111 1111 1111 1111 1111 two = – 1 ten maxint minint MIPS
.5 1999©UCB °Negating a two's complement number: invert all bits and add 1 remember: “negate” and “invert” are quite different! °Converting n bit numbers into numbers with more than n bits: MIPS 16 bit immediate gets converted to 32 bits for arithmetic copy the most significant bit (the sign bit) into the other bits 0010 -> 0000 0010 1010 -> 1111 1010 "sign extension" (lbu vs. lb) Two's Complement Operations
.6 1999©UCB °Just like in grade school (carry/borrow 1s) 0111 0111 0110 + 0110- 0110- 0101 °Two's complement operations easy subtraction using addition of negative numbers 0111 + 1010 °Overflow (result too large for finite computer word): e.g., adding two n-bit numbers does not yield an n-bit number 0111 + 0001 note that overflow term is somewhat misleading, 1000 it does not mean a carry “overflowed” Addition & Subtraction
.7 1999©UCB MIPS ALU Instructions °Add, AddU, Sub, SubU, AddI, AddIU => 2’s complement adder/sub with overflow detection °And, Or, AndI, OrI, Xor, Xori, Nor => Logical AND, logical OR, XOR, nor °SLTI, SLTIU (set less than) => 2’s complement adder with inverter, check sign bit of result
.8 1999©UCB MIPS arithmetic instruction format R-type: I-Type: 3125201550 opRsRtRdfunct opRsRtImmed 16 Typeopfunct ADDI10xx ADDIU11xx SLTI12xx SLTIU13xx ANDI14xx ORI15xx XORI16xx LUI17xx Typeopfunct ADD0040 ADDU0041 SUB0042 SUBU0043 AND0044 OR0045 XOR0046 NOR0047 Typeopfunct 0050 0051 SLT0052 SLTU0053
.9 1999©UCB Refined Requirements (1) Functional Specification inputs: 2 x 32-bit operands A, B, 4-bit mode outputs:32-bit result S, 1-bit carry, 1 bit overflow operations:add, addu, sub, subu, and, or, xor, nor, slt, sltU (2) Block Diagram ALU AB m ovf S 32 4 c
.10 1999©UCB Refined Diagram: bit-slice ALU °Co = a.b + a.Cin + b.Cin °Sum = AB M S 32 4 Ovflw ALU0 a0b0 m cinco s0 ALU0 a31b31 m cinco s31
.11 1999©UCB Seven plus a MUX ? A B 1-bit Full Adder CarryOut Mux CarryIn Result °Design trick 2: take pieces you know (or can imagine) and try to put them together °Design trick 3: solve part of the problem and extend add and or S-select
.12 1999©UCB Additional operations °A - B = A + (– B) form two complement by invert and add one A B 1-bit Full Adder CarryOut Mux CarryIn Result add and or S-select invert Set-less-than? – left as an exercise
.13 1999©UCB °No overflow when adding a positive and a negative number °No overflow when signs are the same for subtraction °Overflow occurs when the value affects the sign: overflow when adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive and get a negative or, subtract a positive from a negative and get a positive °Consider the operations A + B, and A – B Can overflow occur if B is 0 ? Can overflow occur if A is 0 ? Detecting Overflow
.14 1999©UCB °An exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address is saved for possible resumption °Details based on software system / language example: flight control vs. homework assignment °Don't always want to detect overflow — new MIPS instructions: addu, addiu, subu note: addiu still sign-extends! note: sltu, sltiu for unsigned comparisons Effects of Overflow
.15 1999©UCB Overflow Detection °Overflow: the result is too large (or too small) to represent properly Example: - 8 < = 4-bit binary number <= 7 °When adding operands with different signs, overflow cannot occur! °Overflow occurs when adding: 2 positive numbers and the sum is negative 2 negative numbers and the sum is positive °On your own: Prove you can detect overflow by: Carry into MSB ° Carry out of MSB 0111 0011+ 1010 1 1100 1011+ 0111 110 7 3 1 – 6 –4 – 5 7 0
.16 1999©UCB Overflow Detection Logic °Carry into MSB ° Carry out of MSB For a N-bit ALU: Overflow = CarryIn[N - 1] XOR CarryOut[N - 1] A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3 Overflow XYX XOR Y 000 011 101 110
.17 1999©UCB But What about Performance? °Critical Path of n-bit Rippled-carry adder is n*CP A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 CarryOut2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3 Design Trick: throw hardware at it
.18 1999©UCB Carry Look Ahead (Design trick: peek) ABC-out 000“kill” 01C-in“propagate” 10C-in“propagate” 111“generate” A0 B1 S G P P = A and B G = A xor B A B S G P A B S G P A B S G P Cin C1 =G0 + C0 P0 C2 = G1 + G0 P1 + C0 P0 P1 C3 = G2 + G1 P2 + G0 P1 P2 + C0 P0 P1 P2 G C4 =... P
.19 1999©UCB Cascaded Carry Look-ahead (16-bit): Abstraction CLACLA 4-bit Adder 4-bit Adder 4-bit Adder C1 =G0 + C0 P0 C2 = G1 + G0 P1 + C0 P0 P1 C3 = G2 + G1 P2 + G0 P1 P2 + C0 P0 P1 P2 G P G0 P0 C4 =... C0
.20 1999©UCB Additional MIPS ALU requirements °Mult, MultU, Div, DivU (next lecture) => Need 32-bit multiply and divide, signed and unsigned °Sll, Srl, Sra (next lecture) => Need left shift, right shift, right shift arithmetic by 0 to 31 bits °Nor (leave as exercise to reader) => logical NOR or use 2 steps: (A OR B) XOR 1111....1111
.21 1999©UCB °More complicated than addition accomplished via shifting and addition °More time and more area °Let's look at 3 versions based on a gradeschool algorithm 0010 (multiplicand) __x_1011 (multiplier) °Negative numbers: convert and multiply there are better techniques, we won’t look at them Multiplication
.22 1999©UCB Multiplication: Implementation Datapath Control
.23 1999©UCB Final Version What goes here? Multiplier starts in right half of product
.24 1999©UCB Floating Point (a brief look) °We need a way to represent numbers with fractions, e.g., 3.1416 very small numbers, e.g.,.000000001 very large numbers, e.g., 3.15576 10 9 °Representation: sign, exponent, significand: (–1) sign significand 2 exponent more bits for significand gives more accuracy more bits for exponent increases range °IEEE 754 floating point standard: single precision: 8 bit exponent, 23 bit significand double precision: 11 bit exponent, 52 bit significand
.25 1999©UCB IEEE 754 floating-point standard °Leading “1” bit of significand is implicit °Exponent is “biased” to make sorting easier all 0s is smallest exponent all 1s is largest bias of 127 for single precision and 1023 for double precision summary: (–1) sign significand) 2 exponent – bias °Example: decimal: -.75 = - ( ½ + ¼ ) binary: -.11 = -1.1 x 2 -1 floating point: exponent = 126 = 01111110 IEEE single precision: 10111111010000000000000000000000
.26 1999©UCB Floating point addition °
.27 1999©UCB Floating Point Complexities °Operations are more complicated (see text) °In addition to overflow we can have “underflow” °Accuracy can be a big problem IEEE 754 keeps two extra bits, guard and round four rounding modes positive divided by zero yields “infinity” zero divide by zero yields “not a number” other complexities °Implementing the standard can be tricky °Not using the standard can be even worse see text for description of 80x86 and Pentium bug!
.28 1999©UCB Chapter Three Summary °Computer arithmetic is constrained by limited precision °Bit patterns have no inherent meaning but standards do exist two’s complement IEEE 754 floating point °Computer instructions determine “meaning” of the bit patterns °Performance and accuracy are important so there are many complexities in real machines °Algorithm choice is important and may lead to hardware optimizations for both space and time (e.g., multiplication) °You may want to look back (Section 3.10 is great reading!)
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
1 2004 Morgan Kaufmann Publishers Chapter Three.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
Computing Systems Basic arithmetic for computers.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
1 Chapter Three. 2 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
1 1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
1 1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
H.-H. S. Lee 1 ECE3055 Computer Architecture and Operating Systems Lecture 4 Numbers and ALU Prof. Hsien-Hsin Sean Lee School of Electrical and Computer.
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 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
Arithmetic.1 2/15 Computer Arithmetic ALU Performance is critical ( App. C5, C6 4 th ed.)
1 EGRE 426 Fall 09 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
EEL-4713C Ann Gordon-Ross EEL-4713C Computer Architecture Introduction: the Logic Design Process.
1 CSE SUNY New Paltz Chapter Four Arithmetic and Logic Unit Operation Result a b ALU.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
1 Modified from Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers Section 2 citation and following credit line is.
ECE 232 L8.Arithm.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 8 Computer.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
1 ECE369 Chapter 3. 2 ECE369 Multiplication More complicated than addition –Accomplished via shifting and addition More time and more area.
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.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
Computer Architecture Chapter 3 Instructions: Arithmetic for Computer Yu-Lun Kuo 郭育倫 Department of Computer Science and Information Engineering Tunghai.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Computer Architecture Lecture Notes Spring 2005 Dr. Michael P. Frank Competency Area 4: Computer Arithmetic.
1 Modified from Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
1 Chapter Three Last revision: 4/17/ Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
361 design.1 Computer Architecture ECE 361 Lecture 5: The Design Process & ALU Design.
CS151B Computer Systems Architecture Winter 2002 TuTh 2-4pm BH Instructor: Prof. Jason Cong Lecture 5 - ALU Design I: Adder and Simple Logic Operations.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (www.cse.psu.edu/~mji)
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
1 Chapter 3 Arithmetic for Computers Lecture Slides are from Prof. Jose Delgado-Frias, Mr. Paul Wettin, and Prof. Valeriu Beiu (Washington State University.
Arithmetic for Computers CPSC 252 Computer Organization Ellen Walker, Hiram College.
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu (http://tdt.sjtu.edu.cn/~hjzhu/ )http://tdt.sjtu.edu.cn/~hjzhu/
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
© 2017 SlidePlayer.com Inc. All rights reserved.