Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Chapter Three.
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
King Fahd University of Petroleum and Minerals
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
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
MIPS Architecture Arithmetic/Logic Instructions ALU Design – Chapter 4 By N. Guydosh 2/17/04.
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.
1 Lecture 7: Computer Arithmetic Today’s topics:  Chapter 2 wrap-up  Numerical representations  Addition and subtraction Reminder: Assignment 3 will.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Number Systems Computer Science 210 Computer Organization.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
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.
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:
EGRE 426 Fall 09 Chapter Three
Computing Systems Basic arithmetic for computers.
COMPUTER ORGANIZATIONS CSNB123 May 2014Systems and Networking1.
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
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Lecture 11: Chapter 2 Today’s topic –Numerical representations Reminders –Homework 3 posted, due 9/29/2014 –Homework 4 posted, due 10/6/2014 –Midterm 1.
Binary Adder DesignSpring Binary Adders. Binary Adder DesignSpring n-bit Addition –Ripple Carry Adder –Conditional Sum Adder –(Carry Lookahead.
08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Addition, Subtraction, Logic Operations and ALU Design
IT1004: Data Representation and Organization Negative number representation.
CHAPTER 3 Arithmetic For Computers 1/31/ Topics for discussion 1/31/ Number system: { radix/base, a set of distinct digits, operations} Radix.
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.
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
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
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.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
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.
Computer System Design Lecture 3
Computer Arthmetic Chapter Four P&H.
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
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
COMS 361 Computer Organization
Presentation transcript:

Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker

Overview Number representations Overflows Floating point numbers Arithmetic logic units

Unsigned Numbers 32 bits are available Range = = Upper bound 2 32 –1 =

Number representations What signed integer number representations do you know?

Signed Numbers Sign-magnitude representation MSB represents sign, 31bits for magnitude One’s complement Use for non-negative range Invert all bits for negative numbers Two’s complement Same as one’s complement except negative numbers are obtained by inverting all bits and adding 1

Advantages and Disadvantages  sign-magnitude representation  one’s complement representation  two’s complement representation

Signed Numbers (3bits) sign magnitudeone’s complementtwo’s complement = = = = = = = = = = = = = = = = -1

Two’s complement The unsigned sum of an n-bit number its negative yields? Example with 3 bits: = 2 n => negate(x) = 2 n -x Explain one’s complement

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 MIPS 32bit signed numbers

Conversions How do you convert an n-bit number into a 2n-bit number? (Assume two’s complement representation)

Conversions Suppose that you have 3bit two’s complement number = -3 Convert into a 6bit two’s complement number = -3 Replicate most significant bit!

Comparisons What can go wrong if you accidentally compare unsigned with signed numbers?

Comparisons for [un]signed Register $s Register $s Compare registers (set less than) slt $t0, $s0, $s1yes, since –1 < 1 sltu $t1, $s0, $s1 no, since >1

Just like in grade school (carry/borrow 1s) Two's complement operations easy subtraction using addition of negative numbers Addition & Subtraction

Overflow means that the result is too large for a finite computer word for example, adding two n-bit numbers does not yield an n-bit number  the term overflow is somewhat misleading Overflow

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 Detecting Overflow

OperationOperand AOperand BOverflow if result A+B>=0 <0 A+B<0 >=0 A-B>=0<0 A-B<0>=0

An exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address is saved for possible resumption Don't always want to detect overflow MIPS instructions: addu, addiu, subu note: addiu still sign-extends! Effects of Overflow

What next? More MIPS assembly operations How does an ALU work? Simple digital logic design How can we speed-up addition? What about multiplication?