CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
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)
COMP3221 lec05-numbers-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 5: Number Systems – I
1 CSE1301 Computer Programming Lecture 29: Number Representation (Part 1)
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 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.
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
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.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Number Systems Lecture 02.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Arithmetic for Computers
CENG 311 Machine Representation/Numbers
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Lecture 5.
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.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
IT253: Computer Organization
Computing Systems Basic arithmetic for computers.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 2.
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.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
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.
Fixed & Floating Number Format Dr. Hugh Blanton ENTC 4337/5337.
Integer and Fixed Point P & H: Chapter 3
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Cs641 pointers/numbers.1 Overview °Stack and the Heap °malloc() and free() °Pointers °numbers in binary.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 23: Aritmatika 18 Desember 2002 Bobby Nazief Johny Moningka
IT1004: Data Representation and Organization Negative number representation.
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.
Numbers in Computers.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
Number Representation (Part 2) Computer Architecture (Fall 2006)
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.
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.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
Lecture 7: MARS, Computer Arithmetic
Computer Science 210 Computer Organization
March 2006 Saeid Nooshabadi
Lecture 8: Addition, Multiplication & Division
Computer Science 210 Computer Organization
Lecture 8: Addition, Multiplication & Division
Data Representation Data Types Complements Fixed Point Representation
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
COMS 361 Computer Organization
Presentation transcript:

CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, ©2005 Some slides and/or pictures in the following are adapted from: slides ©2008 UCB 10

So far, unsigned numbers Obvious solution: define leftmost bit to be sign! –0  +, 1  – –Rest of bits can be numerical value of number Representation called sign and magnitude MIPS uses 32-bit integers. +1 ten would be: And –1 ten in sign and magnitude would be: How to Represent Negative Numbers?

Arithmetic circuit complicated –Special steps depending whether signs are the same or not Also, two zeros – 0x = +0 ten – 0x = –0 ten –What would two 0s mean for programming? Therefore sign and magnitude abandoned Shortcomings of sign and magnitude?

Example: 7 10 = –7 10 = Called One’s Complement Note: positive numbers have leading 0s, negative numbers have leadings 1s What is ? Answer: How many positive numbers in N bits? How many negative numbers? Another try: complement the bits

Arithmetic still somewhat complicated Still two zeros – 0x = +0 ten – 0xFFFFFFFF = -0 ten Although used for awhile on some computer products, one’s complement was eventually abandoned because another solution was better Shortcomings of One’s complement?

32 bits can only represent 2 32 numbers – if we wish to also represent negative numbers, we can represent 2 31 positive numbers (incl zero) and 2 31 negative numbers two = 0 ten two = 1 ten … two = two = two = -(2 31 – 1) two = -(2 31 – 2) … two = two = -1 Negative Numbers

two = 0 ten two = 1 ten … two = two = two = -(2 31 – 1) two = -(2 31 – 2) … two = two = -1 Why is this representation favorable? Consider the sum of 1 and -2 …. we get -1 Consider the sum of 2 and -1 …. we get +1 This format can directly undergo addition without any conversions! Each number represents the quantity x x x … + x x ’s Complement

two = 0 ten two = 1 ten … two = two = two = -(2 31 – 1) two = -(2 31 – 2) … two = two = -1 Note that the sum of a number x and its inverted representation x’ always equals a string of 1s (-1) x + x’ = -1 x’ + 1 = -x … hence, can compute the negative of a number by -x = x’ + 1 inverting all bits and adding 1 Similarly, the sum of x and –x gives us all zeroes, with a carry of 1 In reality, x + (-x) = 2 n … hence the name 2’s complement 2’s Complement

2 N-1 non- negatives 2 N-1 negatives one zero how many positives? ’s Complement Number “line”: N = 5

Compute the 32-bit 2’s complement representations for the following decimal numbers: 5, -5, -6 Example

What if too big? Binary bit patterns above are simply representatives of numbers. Strictly speaking they are called “numerals” Numbers really have an  number of digits –with almost all being same (00…0 or 11…1) except for a few of the rightmost digits –Just don’t normally show leading digits If result of add (or -, *, / ) cannot be represented by these rightmost HW bits, overflow is said to have occurred unsigned

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

For an unsigned number, overflow happens when the last carry (1) cannot be accommodated For a signed number, overflow happens when the most significant bit is not the same as every bit to its left – when the sum of two positive numbers is a negative result – when the sum of two negative numbers is a positive result – The sum of a positive and negative number will never overflow MIPS allows addu and subu instructions that work with unsigned integers and never flag an overflow – to detect the overflow, other instructions will have to be executed

The hardware recognizes two formats: unsigned (corresponding to the C declaration unsigned int ) -- all numbers are positive, a 1 in the most significant bit just means it is a really large number signed (C declaration is signed int or just int ) -- numbers can be +/-, a 1 in the MSB means the number is negative This distinction enables us to represent twice as many numbers when we’re sure that we don’t need negatives Signed / Unsigned

Consider a comparison instruction: slt $t0, $t1, $zero and $t1 contains the 32-bit number …01 What gets stored in $t0 ? The result depends on whether $t1 is a signed or unsigned number – the compiler/programmer must track this and accordingly use either slt or sltu slt $t0, $t1, $zero stores 1 in $t0 sltu $t0, $t1, $zero stores 0 in $t0 MIPS Instructions

Occasionally, 16-bit signed numbers must be converted into 32-bit signed numbers – for example, when doing an add with an immediate operand The conversion is simple: take the most significant bit and use it to fill up the additional bits on the left – known as sign extension So 2 10 goes from to and goes from to Sign Extension

Quiz X = two Y = two A.X > Y (if signed) B.X > Y (if unsigned) AB 1: FF 2: FT 3: TF 4: TT

Computers are made to deal with numbers What can we represent in N bits? –2 N things, and no more! They could be… –Unsigned integers: 0to2 N - 1 (for N=32, 2 N –1 = 4,294,967,295) –Signed Integers (Two’s Complement) -2 (N-1) to 2 (N-1) - 1 (for N=32, 2 (N-1) = 2,147,483,648) Review of Numbers

1.Very large numbers? (seconds/millennium)  31,556,926, ( x ) 2.Very small numbers? (Bohr radius)  m ( x ) 3.Numbers with both integer & fractional parts?  1.5 First consider #3 …our solution will also help with 1 and 2 What about other numbers?

Representation of Fractions “Binary Point” like decimal point signifies boundary between integer and fractional parts: xx. yyyy Example 6-bit representation: = 1x x x2 -3 = If we assume “fixed binary point”, range of 6-bit representations with this format: 0 to (almost 4)