CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.

Slides:



Advertisements
Similar presentations
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Advertisements

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Chapter Three.
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
1  2004 Morgan Kaufmann Publishers Chapter Three.
Faculty of Computer Science © 2006 CMPUT 229 Representing Information Numbers, Numbers, and Numbers.
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
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.
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.
Lecture Objectives: 1)Explain the relationship between addition and subtraction with twos complement numbering systems 2)Explain the concept of numeric.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
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:
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.
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
Operations on Bits Arithmetic Operations Logic Operations
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.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
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.
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
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
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.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
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 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
CS 230: Computer Organization and Assembly Language
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:

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB

CML CMLAnnouncements Quiz 2 –Complete Chapter 2 MIPS Assembly Language Programming, including function calls –Thursday, Sept 24, 2009 Project 2 –MIPS Assembly Language Programming, including function calls –Will take a day or two to program –Due tomorrow

CML CML CSE 230 Road map So far –Write any program in MIPS assembly language –Convert into binary instructions Today –How are numbers represented –How are they added, subtracted, multiplied divided

CML Numbers Bits are just bits (no inherent meaning) –conventions define relationship between bits and numbers Unsigned Numbers – Large Numbers –Avogadro's number × ~ 64 bits Signed Numbers –How to represent –ve numbers Fractions –How to represent

CML CML Unsigned Numbers Representation (d 31 d 30 … d 2 d 1 d 0 ) 2 = d 31 * d 30 * … d 2 *2 2 + d 1 * d 0 * = = = = 4,294,967, Minimum Number = 0 = (0000….0000) 2 Maximum Number = (1111….1111) 2 = (1 0000….0000) 2 – 1 =

CML CML Addition of Unsigned Numbers Addition What happens when –Addition results in a number that does not fit in 32-bits = 2*2 32 – 2 = needs 33 bits –Overflow

CML CML Subtraction of Unsigned Numbers Subtraction What happens when –You subtract greater number from smaller number Need –ve numbers

CML CML Signed Numbers One simple strategy –Sign Magnitude Representation Leftmost bit is sign bit Rest 31-bits are unsigned –Representation (d 31 d 30 … d 2 d 1 d 0 ) 2 = (-1)*d 31 + d 30 * … d 2 *2 2 + d 1 * d 0 *2 0 –Number Range = -( ), …,-1,-0, +0,+1, …, +( ) 2 zero’s –How to find –ve of a number Just change the sign-bit –Addition & Subtraction Add/Sub the 31-bits, and change the sign bit logically Need a seamless way to perform these very frequent operations 31-bit magnitude 1-bit sign

CML CML 2s Complement Representation Representation (d 31 d 30 … d 2 d 1 d 0 ) 2 = d 31 *(-2) 31 + d 30 * … d 2 *2 2 + d 1 * d 0 *2 0 Examples 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

CML CML Negate 2's Complement Number Negating a two's complement number: invert all bits and add 1 –remember: “negate” and “invert” are quite different! two = + 2 ten two = – 2 ten Converting n bit numbers into numbers with more than n bits: –MIPS 16 bit immediate gets converted to 32 bits for arithmetic "sign extension" –copy the most significant bit (the sign bit) into the other bits > >

CML CML Add 2’s Complement Numbers Just like unsigned numbers = =

CML CML Subtract 2’s Complement Numbers A – B = A + (-B) = A + (!B + 1) Just like unsigned numbers 6 – 7 = 6 + (~7 + 1) = – 5 = -3 + (~(5)+1) =

CML CMLOverflow When result of operation too large to fit in 32-bits 7 – (-13) = 20 Detect Overflows –Positive + Positive -> Negative –Negative + Negative -> Positive –Positive – Negative -> Negative –Negative – Positive -> Positive Consider the operations A + B, and A – B –Can overflow occur if B is 0 ? –Can overflow occur if A is 0 ?

CML CML Effects of Overflow 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

CML CML Yoda says… Luke: I can’t believe it. Yoda: That is why you fail