Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,

Slides:



Advertisements
Similar presentations
Datorteknik IntegerAddSub bild 1 Integer arithmetic Depends what you mean by "integer" Assume at 3-bit string. –Then we define zero = 000 one = 001 Use.
Advertisements

Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
HEXADECIMAL NUMBERS Code
When NOT to use Unsigned? Don’t Use Just Because Number Nonzero – C compilers on some machines generate less efficient code unsigned i; for (i = 1; i
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Binary Addition Rules Adding Binary Numbers = = 1
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
Fixed-Point Arithmetics: Part I
1 COMP541 Arithmetic Circuits Montek Singh Mar 20, 2007.
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.
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
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.
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we.
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
IT253: Computer Organization
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Bits, Data Types, and Operations Slides based on set prepared by Gregory T. Byrd, North Carolina State University.
Positional Number Systems
ECEN 248 Lab 4: Multiplexer Based Arithmetic Logic Unit
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Integer and Fixed Point P & H: Chapter 3
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
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=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Chapter 4 Integer Data Representation. Unsigned Integers.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
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.
Numerical formats What’s the main idea? Want to represent numbers (eg: 45, -12, ) using only bits. We’ve already seen (or you can read in the book)
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.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Representing Positive and Negative Numbers
Chapter 4 Operations on Bits.
CSCI206 - Computer Organization & Programming
Exercise: Add these two single precision IEEE 754 numbers: … …0 Left number: 1.101x24 Right number: 1.011x 22= x24.
MIPS ALU.
CSCI206 - Computer Organization & Programming
MIPS ALU.
Decimal and binary representation systems
A 1-Bit Arithmetic Logic Unit
March 2006 Saeid Nooshabadi
CSC 220: Computer Organization Signed Number Representation
Integer arithmetic Depends what you mean by "integer"
COMS 361 Computer Organization
Presentation transcript:

Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero, one and binary addition: Zero 000 One Zero + one = one. Makes sense!

Computer Engineering page 2 Add one repeatedly, use up all possible patterns: Zero Called the; Unsigned Integer System. No negative integers!

Computer Engineering page 3 Two additions:

Computer Engineering page 4 Two additions: Yes! 5 = But 001 represents one. is = 1???

Computer Engineering page 5 Addition of unsigned integers Error detected by presence of “carry”

Computer Engineering page 6 How do we subtract unsigned integers? We need the concept of the; “ Two’s complement”

Computer Engineering page 7 One’s complement Take any string; Invert every bit; 0 1 This is One’s complement. "NOT”.

Computer Engineering page 8 Two’s complement Given a string; One's complement; then add one. This is called; two’s complement

Computer Engineering page 9 To subtract unsigned A- B Perform: A + 2’s compl (B) = A + Not (B) + 1

Computer Engineering page 10 Example: Carry! =2; Good! No Carry! =6; BAD!

Computer Engineering page 11 Subtraction of unsigned integers Error detected by absence of carry! –Warning: Some machines invert the carry bit on subtraction –So that "carry" => Error for both add and sub

Computer Engineering page 12 Conclusion For unsigned arithmetic we are interested in carry Pay attention! I never used the word "overflow" that's something completely different. Also notice: –3-bit operands gave 3-bit results. –Don't be tempted to write that 4'th bit down!

Computer Engineering page 13 How about negative numbers? How should we represent -1 ? How would we compute 0 - 1? 0 + 2's compl (1) We choose this as our "-1" 1 = =

Computer Engineering page 14 Repeatedly add -1: Zero Less than zero No! High order bit called "sign bit"

Computer Engineering page 15 Signed 3-bit integers Not symmetrical around zero!!!

Computer Engineering page 16 Sign bit The high order bit in a number Also called "N"-bit Value is negative when this bit is "1"

Computer Engineering page 17 Let's try A + B (-1) *000 Both results is OK But: Left case: no carry Right case: carry Conclusion: For signed addition carry is worthless Same conclusion for signed subtraction * carry

Computer Engineering page 18 Some additions A (-3) (-4) (-2)

Computer Engineering page 19 Some additions B (-3) (-4) C C (-2)

Computer Engineering page 20 Some additions C OK BAD (-3) (-4) C C OK BAD (-2) OK OK

Computer Engineering page 21 Some additions D OK BAD (-3) (-4) C C OK BAD (-2) OK OK

Computer Engineering page 22 Error during signed addition: R = A + B A, B same sign and R opposite sign called overflow Notice: Mathematically, signed addition is the same as unsigned addition The same is true for signed subtraction and unsigned subtraction A - B –> A + (-B) –> A + 2's compl (B)

Computer Engineering page 23 Some subtractions A (-1) (-1)

Computer Engineering page 24 Some subtractions B (-1) C (-1) C C C 0 1 1

Computer Engineering page 25 Some subtractions C (-1) C OK BAD (-1) C OK OK C C OK BAD

Computer Engineering page 26 Some subtractions D (-1) C OK BAD (-1) C OK OK C C OK BAD

Computer Engineering page 27 Error during signed subtraction: R = A - B A, B different sign and B, R same sign called overflow

Computer Engineering page 28 Arithmetic- logic unit (ALU) C = carry V = overflow N = sign bit of R Z = 1 if R = 0 32 A B C Operation Condition codes C, V, N, Z

Computer Engineering page 29 Compare two unsigned numbers? is A < B ? Easy! Compute A - B and examine carry But – to compare two signed numbers? is A < B ? Most common mistake: –Compute R = A - B, then look at sign of R. –If R < 0 then A < B (N-bit) Not good enough!

Computer Engineering page 30 To compare two signed numbers: What about –A = - 4 –B = 3 – – – c 001 “If R neg then A < B” – We conclude A ≥ B, that is - 4 ≥ 3 Wrong!

Computer Engineering page 31 Some examples A (-1) (-1)

Computer Engineering page 32 Some examples B (-1) C < +1? No! 3 < -1? No! (-1) C < -1? No! 1 < -1? No! C C < +1? Yes! -4 < 1? Yes!

Computer Engineering page 33 Some examples C (-1) C < +1? No! 3 < -1? No! N = 0, V = 0 N = 1, V = (-1) C < -1? No! 1 < -1? No! N = 0, V = 0 N = 0, V = C C < +1? Yes! -4 < 1? Yes! N = 1, V = 0 N = 0, V = 1

Computer Engineering page 34 To compare signed numbers: Compute R = A - B A < B true if N and V are different A<B = exor(N,V) after computation