Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.

Slides:



Advertisements
Similar presentations
Lec 12Systems Architecture1 Systems Architecture Lecture 12: Design of the MIPS ALU Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
Advertisements

Chapter Three.
Systems Architecture Lecture 5: MIPS Instruction Set
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
COE 202: Digital Logic Design Signed Numbers
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
CHAPTER 4: Representing Integer Data The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Assembly Language and Computer Architecture Using C++ and Java
1  2004 Morgan Kaufmann Publishers Chapter Three.
Assembly Language and Computer Architecture Using C++ and Java
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
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.
Introduction to Number Systems
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Number Systems Lecture 02.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Arithmetic for Computers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CENG 311 Machine Representation/Numbers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
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:
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1  2004 Morgan Kaufmann Publishers Instructions: bne $t4,$t5,Label Next instruction is at Label if $t4≠$t5 beq $t4,$t5,Label Next instruction is at Label.
EGRE 426 Fall 09 Chapter Three
Computing Systems Basic arithmetic for computers.
CSE 111 Representing Numeric Data in a Computer Slides adapted from Dr. Kris Schindler.
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
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.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
Positional Number Systems
Binary Adder DesignSpring Binary Adders. Binary Adder DesignSpring n-bit Addition –Ripple Carry Adder –Conditional Sum Adder –(Carry Lookahead.
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Computer Architecture Lecture Notes Spring 2005 Dr. Michael P. Frank Competency Area 4: Computer Arithmetic.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Prof. Hsien-Hsin Sean Lee
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.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
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 Chapter 3 Arithmetic for Computers Lecture Slides are from Prof. Jose Delgado-Frias, Mr. Paul Wettin, and Prof. Valeriu Beiu (Washington State University.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Computer System Design Lecture 3
Ch 3: Computer Arithmetic
Systems Architecture I
Systems Architecture I (CS ) Lecture 16: Exceptions
Arithmetic Logical Unit
Topic 3a Two’s Complement Representation
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
A 1-Bit Arithmetic Logic Unit
Chapter 3 Arithmetic for Computers
Systems Architecture I (CS ) Lecture 17: Exceptions
COMS 361 Computer Organization
Presentation transcript:

Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all figures from Computer Organization and Design: The Hardware/Software Approach, Third Edition, by David Patterson and John Hennessy, are copyrighted material (COPYRIGHT 2004 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED).

Lec 11Systems Architecture2 Introduction Objective: To learn about computer arithmetic and how number are represented in computers –Review binary and hexadecimal numbers –Negative numbers signed-magnitude two's complement –Two's complement numbers –Addition and subtraction –Representation: a number A = –Example for base 2 (binary): 1011 = 1 x x x x 2 0

Lec 11Systems Architecture3 Bits have no inherent meaning — conventions define relationship between bits and numbers Binary numbers (base 2) decimal: n -1 Complications: 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? –Which bit patterns will represent which numbers? Numbers

Lec 11Systems Architecture4 Sign Magnitude: One's Complement: Two's Complement : 000 = = = = = = = = = = = = = = = = = = = = = = = = -1 Issues: balance, number of zeros, ease of operations Which one is best? Why? Possible Representations

Lec 11Systems Architecture5 Radix-minus-one complement Radix-complement (the complement) Radix-complement is the inverse with respect to addition A 4-digit decimal example: The following equation holds when subtracting one number from another in FIXED decimal width: Y = B – A + ( ) = B + ( A + 1) – = B + ([9999 – A] + 1) – Observe: 9999 – A is 9-complement (radix-minus-one complement) Observe: [9999 – A] + 1 is 10-complement (THE radix complement) The Complement – Theory

Lec 11Systems Architecture6 No borrowing is necessary when subtracting Due to fixed width of the registers, the leading 1 is lost automatically due to carry overflow. Why the Complement? – Example

Lec 11Systems Architecture7 Modular arithmetic (mod n): a ≡ b (mod n), i.e., a = b + qn [a] = { a + qn | for all q in Z }, i.e., all number equivalent to a mod n. This forms a residue class ring Z n. What is a ring? It is a group where addition is as expected and addition has well-defined inverse. (This is not precise.) That is [a] + [b] = [a + b] and [a] x [b] = [a x b] Two's Complement – Why does it work?

Lec 11Systems Architecture8 Example: Z 8  [0], [1], [2], …, [7] is a residue class ring of 8 elements. For this example, we can use other representations: 0, 1, 2, 3, -4, -3, -2, -1 because these numbers are equivalent, e.g. 4 ≡ -4 (mod 8), etc… Binary addition in k bits is equivalent to addition in Z 2 k ring. In k-bits, the largest number will be = 011…11 = 2 k-1 -1 In k-bits, the smallest number will be = 100…00 = -2 k-1 Representation: b k-1 …b 0 = -b k-1 2 k-1 +b k-2 2 k-2 +…b b Two's Complement – Why it works?

Lec 11Systems Architecture9 Let a k-bit number X have a two’s complement inverse 2 X with respect to Z 2 k ring, i.e., X + 2 X ≡ 0 (mod 2 k ). For instance, mod 8 ≡ 0! Let 1 X be a one’s complement of X (i.e., radix-minus-one complement, which is equivalent to flipping all the bits in binary). By definition, 2 X = 1 X + 1 and X + 1 X = 2 k – 1 Therefore, X + 2 X = 2 k ≡ 0 mod 2 k Two's Complement – Inversion

Lec 11Systems Architecture10 32 bit signed numbers: two = 0 ten two = + 1 ten two = + 2 ten two = + 2,147,483,646 ten two = + 2,147,483,647 ten two = – 2,147,483,648 ten two = – 2,147,483,647 ten two = – 2,147,483,646 ten two = – 3 ten two = – 2 ten two = – 1 ten maxint minint MIPS signed numbers

Lec 11Systems Architecture11 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 > > –"sign extension" (lbu vs. lb) Two's Complement Operations

Lec 11Systems Architecture12 Sign extension involves propagating the sign bit to increase the bit-size of the number. Why this works? Number before sign extension: b k-1 …b 0 = -b k-1 2 k-1 +b k-2 2 k-2 +…b b Number after sign extension by one bit: b k …b 0 = -b k 2 k +b k-1 2 k-1 +b k-2 2 k-2 +…b b This is equivalent to adding 2 k-1 and subtracting 2 k, i.e., subtracting 2 k - 2 k-1 = 2 k-1 *(2-1) It is obvious why this works for positive numbers… Two's Complement – Sign Extension

Lec 11Systems Architecture13 Just like in grade school (carry/borrow 1s) Two's complement operations easy –subtraction using addition of negative numbers Overflow (result too large for finite computer word): –e.g., adding two n-bit numbers does not yield an n-bit number note that overflow term is somewhat misleading, 1000 it does not mean a carry “overflowed” Addition & Subtraction

Lec 11Systems Architecture14 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

Lec 11Systems Architecture15 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