Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Chapter Three.
©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,
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
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
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 6 - Logic &
1 Chapter 4: Arithmetic for Computers (Part 1) CS 447 Jason Bakos.
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.
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.
Computer Science 210 Computer Organization The Arithmetic Logic Unit.
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.
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
Computing Systems Designing a basic ALU.
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Ch3a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Crunching Numbers Topics we need to explore Representing numbers on a computer.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
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.
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu ( )
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
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.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
Prof. Hsien-Hsin Sean Lee
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
1 Arithmetic Where we've been: –Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: –Implementing the Architecture.
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
Computer Arthmetic Chapter Four P&H.
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Arithmetic Where we've been:
Arithmetic Logical Unit
Topic 3a Two’s Complement Representation
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
MIPS Assembly.
COMS 361 Computer Organization
A 1-Bit Arithmetic Logic Unit
Chapter 3 Arithmetic for Computers
MIPS Assembly.
COMS 361 Computer Organization
Presentation transcript:

Arithmetic I CPSC 321 Andreas Klappenecker

Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm

Any Questions?

What happened so far? We learned the basics of the MIPS assembly language We briefly touched upon the translation to machine language We formulated our goal, namely the implementation of a MIPS processor.

Pipelined MIPS Processor

Welcome to the Future! The execution of machine instructions can follow, for example, the steps: Instruction fetch Instruction decode and register read Execute opn. or calculate an address Access operand in data memory Write the result into a register

Pipelined MIPS Processor We concentrate first on the arithmetic-logic unit

The Arithmetic-Logic Unit Arithmetic (addition and subtraction) we need to know number representations there exist various interesting algorithms for addition and subtraction integer and floating point arithmetic Logical operations (and, or, not)

Computer Arithmetic

Unsigned Numbers 32 bits are available Range = = Upper bound 2 32 –1 = 4,294,967,295

Unsigned Numbers If we have n bit unsigned integers, then addition really means a+b mod 2 n For example, if n=4, then = = 22 = 6 mod =0110 2

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

One’s Complement Suppose we want to express -30 as an 8bit integer in one’s complement representation. 30 = Invert the bits to obtain the negative number: -30 =

Two’s Complement Suppose we want to express -30 as an 8bit integer in two’s complement representation. 30 = Invert the bits to obtain the negative number: Add one: -30 =

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 and 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, $s1true, since –1 < 1 sltu $t1, $s0, $s1 false, since >1

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

MIPS instructions lb loads a byte and stores the sign- extended version in a word. lbu loads a byte and stores it in a word Which of these two is typically used to process characters?

Overflow means that the result is too large for a finite computer word. For instance, adding two n-bit numbers does not yield an n-bit number. Suppose we add two 3-bit numbers 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

Building an Arithmetic Logic Unit

Logic Gates: AND a b c a b c

Logic Gates: OR a b c a b c

Let's build an ALU to support the andi and ori instructions Selection of operation 0 = and, 1 = or we'll just build a 1 bit ALU, and use 32 of them Possible Implementation (sum-of-products): b a operation result An ALU (arithmetic logic unit)

Selects one of the inputs to be the output, based on a control input Build (and/or) ALU using a MUX S C A B 0 1 The Multiplexor note: it is called a 2-input mux even though it has 3 inputs!

Not easy to decide the “best” way to build something Don't want too many inputs to a single gate for our purposes, ease of comprehension is important Don’t want to have to go through too many gates Let's look at a 1-bit ALU for addition: Different Implementations c out = a b + a c in + b c in sum = a xor b xor c in

Different Implementations How could we build a 1-bit ALU for add, and, and or? How could we build a 32-bit ALU?

Building a 32 bit ALU

Two's complement approach: just negate b and add. How do we negate? A solution: What about subtraction (a – b) ?