COMS 361 Computer Organization

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Chapter Three.
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.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Fixed-Point Arithmetics: Part I
1  2004 Morgan Kaufmann Publishers Chapter Three.
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.
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.
CSE20 Lecture 3 Number Systems: Negative Numbers 1.Sign and Magnitude Representation 2.1’s Complement Representation 3.2’s Complement Representation 1.
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.
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.
Computing Systems Basic arithmetic for computers.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.
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.
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.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
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
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 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
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.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Lecture 4: Digital Systems & Binary Numbers (4)
Representing Positive and Negative Numbers
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
Cosc 2150: Computer Organization
Computer Arthmetic Chapter Four P&H.
Addition and Subtraction
Negative Numbers and Subtraction
Computer Science 210 Computer Organization
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
MIPS ALU.
Lecture 8: Addition, Multiplication & Division
Computer Science 210 Computer Organization
Lecture 8: Addition, Multiplication & Division
The University of Adelaide, School of Computer Science
MIPS ALU.
Topic 3a Two’s Complement Representation
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
CS/COE0447 Computer Organization & Assembly Language
EEL 3705 / 3705L Digital Logic Design
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
COMS 161 Introduction to Computing
CS/COE0447 Computer Organization & Assembly Language
CPS120: Introduction to Computer Science
A 1-Bit Arithmetic Logic Unit
Basic Building Blocks Multiplexer Demultiplexer Adder +
Chapter 3 Arithmetic for Computers
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
Basic Building Blocks Multiplexer Demultiplexer Adder +
Chapter3 Fixed Point Representation
Two’s Complement & Binary Arithmetic
Presentation transcript:

COMS 361 Computer Organization Title: Number Representations Date: 10/28/2004 Lecture Number: 16

Announcements Homework 7 Due Tuesday, 11/02/2004

Review Addressing modes Representing numbers in binary Unsigned (magnitude) Sign-magnitude Addition Subtraction

Outline Representing numbers in binary Problems One’s complement Unsigned (magnitude) Sign-magnitude One’s complement Two’s complement

Problems Unsigned (magnitude) Sign-magnitude No representation for negative numbers Sign-magnitude Two representations for zero, +0 and -0 Arithmetic operations do not always produce the correct answer in the sign-magnitude representation

One’s compliment Positive integers have the most significant bit (leftmost) equal to 0 The magnitude of positive numbers is the same as the signed magnitude representation Negative integers have the most significant bit equal to 1 Negative numbers in n-bit one’s complement has the same binary representation as the unsigned binary number given by:

One’s compliment Unsigned decimal One’s complement Signed decimal 000 000 1 001 2 010 3 011 4 100 -3 5 101 -2 6 110 -1 7 111 -0 -3 = 23 – 1 – 3 = 8 – 4 = 4 -2 = 23 – 1 – 2 = 8 – 3 = 5 -1 = 23 – 1 – 1 = 8 – 2 = 6 -0 = 23 – 1 – 0 = 8 – 1 = 7

One’s compliment Example: let n = 8, and N = 5 There is something special here and in the previous table Negatives are made from the positive by inverting each bit! Simpler hardware for arithmetic operations Still two representations of zero

One’s complement

One’s complement Mathematical operations sometimes give an incorrect result using this representation Two representations of zero 4 – 3 = 4 + -3 = 1 4 – 2 = 4 + -2 = 2 1 1 4 0100 4 0100 +(-3) +1100 +(-2) +1101 1 1 2 1 1 1

Two’s Complement Positive integers have the most significant bit (leftmost) equal to 0 The magnitude of positive numbers is the same as signed magnitude and one’s complement representations Negative integers have the most significant bit (leftmost) equal to 1 Negative numbers in n-bit one’s complement has the same binary representation as the unsigned binary number given by:

Two’s Complement Example: let n = 8, and N = 5 There is a relationship between one’s and two’s complement numbers ones’ complement two’s complement Two’s complement representation can be computed from a numbers one’s complement representation simple by adding one

Two’s Complement It is simple to determine the representation of a negative number in one’s complement given the unsigned (magnitude) representation Use the formula Invert the bits It is easy to convert a one’s complement representation to a two’s complement representation by simply adding 1 to the one’s complement representation

Two’s Complement

Two's Complement Subtraction Two's complement operations easy Subtraction using addition of negative numbers X - Y = X + (-Y) Build an adder for addition, use it for subtraction! X = 6, Y = 5 X-Y = 6+(-5) 0110 +1011 10001

Arithmetic Two's complement mathematical operations Compute the correct answer In the two’s complement representation Two’s complement is used in nearly all computers today X = 4, Y = 3 X - Y = 4 - 3 = 4 + (-3) 0100 +1101 0001 X = 5, Y = 6 X - Y = 5 - 6 = 5 + (-6) 0101 +1010 1111

Two’s complement Sign Bit Sign Extension All negative numbers have a 1 in the most significant bit Hardware need test only this bit to determine if the number is positive or negative Sign Extension Duplicate the sign in all bits to the left in a larger representation of a number 0010 -> 0000 0010 1010 -> 1111 1010

Two’s complement Load byte (lb) assumes an signed byte and sign extends the 24 left most bits Load byte unsigned (lbu) do not sign extend

Two’s complement Addresses Signed integers represent values Start at 0 and continue to the largest address Represented with an unsigned integer Signed integers represent values Important when comparing two numbers A 1 in the sign bit may mean the number is negative and is less than all numbers with a 0 in the sign bit A 1 in the sign bit may mean the number is positive and larger than all numbers with a 0 in this position

Two’s complement Comparing numbers Signed comparison Set on less than (slt) Set on less than immediate (slti) Unsigned comparison Set on less than unsigned (sltu) Set on less than unsigned immediate (sltui)

Two’s complement Overflow A value to large for its representation Represent the number 300 using 8 bits The sign bit is 0 when the number is negative or a 1 when the number is positive

Two's ComplementOverflow Overflow cannot occur Adding two operands of opposite sign Both operands must be represented Sum can be no larger than one of the operands Subtracting two operands of the same sign Subtraction done by negating and add Adding numbers of opposite sign

Two's Complement Overflow Overflow can occur Adding two positive numbers with a negative result Adding two negative numbers with a positive result Needed one extra bit to contain the sign Real sign bit is set to a value not to a sign Only the sign bit is wrong Carry out into the sign bit 0 1 1 1 + 0 0 0 1 1 0 0 0 1 4-bit two’s complement numbers

Two's Complement Overflow Overflow can occur Subtracting a negative number from a positive number with a negative result Subtracting a positive number from a negative number with a positive result

Unsigned Overflow Ignore overflow in unsigned numbers MIPS has different arithmetic instructions for two’s complement and unsigned numbers Signed (Overflow) add, addi, sub (Unsigned) No overflow addu, addiu, subu C/C++ ignores overflow Compilers always generate unsigned instructions

Overflow detection MIPS using an exception (interrupt) Unscheduled function call Next instruction executed is the first in the exception routine Usually a predefined address Upon completion of the exception, normal program execution continues