COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
HEXADECIMAL NUMBERS Code
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
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
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
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.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Fixed-Point Arithmetics: Part I
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Machine Representation/Numbers Lecture 3 CS 61C Machines Structures Fall 00 David Patterson U.C. Berkeley
COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)
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.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
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.
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.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
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
Lecture 5.
Computers Organization & Assembly Language
The 8051 Microcontroller and Embedded Systems
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
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.
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
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.
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
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.
IT1004: Data Representation and Organization Negative number representation.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Lecture 7. Subtractor Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
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,
Lecture 4: Digital Systems & Binary Numbers (4)
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Negative Binary Numbers
March 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
Addition and Substraction
COMP3221: Microprocessors and Embedded Systems
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
March 2006 Saeid Nooshabadi
Computer Organization COMP 210
ECE 331 – Digital System Design
COMS 361 Computer Organization
Presentation transcript:

COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II August, 2003 Saeid Nooshabadi

COMP3221 lec06-numbers-II.2 Saeid Nooshabadi Overview °Signed Numbers: 2’Complement representation °Addition, Subtraction and Comparison in 2’s Complement °Comparison in signed and unsigned numbers °Condition code flags

COMP3221 lec06-numbers-II.3 Saeid Nooshabadi Limits of Computer Numbers °Bits can represent anything! °Characters? 26 letter => 5 bits upper/lower case + punctuation => 7 bits (in 8) (ASCII) rest of the world’s languages => 16 bits (unicode) °Logical values? 0 -> False, 1 => True °colors ? °locations / addresses? commands? °but N bits => only 2 N things

COMP3221 lec06-numbers-II.4 Saeid Nooshabadi Review: Two’s Complement two = 0 ten two = 1 ten two = 2 ten two = 2,147,483,645 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 °One zero, 31st bit => >=0 or <0, called sign bit but one negative with no positive –2,147,483,648 ten

COMP3221 lec06-numbers-II.5 Saeid Nooshabadi Review: Two’s Complement Formula °Recognizing role of sign bit, can represent positive and negative numbers in terms of the bit value times a power of 2: d 31 x d 30 x d 2 x d 1 x d 0 x 2 0 °Example two = 1x x x x2 2 +0x2 1 +0x2 0 = = -2,147,483,648 ten + 2,147,483,644 ten = -4 ten

COMP3221 lec06-numbers-II.6 Saeid Nooshabadi Review: Two’s complement shortcut: Negation °Invert every 0 to 1 and every 1 to 0, then add 1 to the result Sum of number and its inverted representation must be two two = -1 ten Let x’ mean the inverted representation of x Then x + x’ = -1 => x + x’ + 1 = 0 => x’ + 1 = -x °Example: -4 to +4 to -4 x : two x’: two +1: two ()’: two +1: two

COMP3221 lec06-numbers-II.7 Saeid Nooshabadi Two’s Complement’s Arithmetic Example °Example: 20 – 4 = 16 °20 – 4 == 20 + (–4) x : two – Y: two x: two + – Y: two X + (–Y): two 1 Ignore Carry out

COMP3221 lec06-numbers-II.8 Saeid Nooshabadi Two’s Complement’s Arithmetic Example °Example: –2,147,483,648 –2 = –2,147,483,650 ? x : two – Y: two x: two + – Y: two X + (–Y): two two = 2,147,483,646 ten  – 2,147,483,650 ten OVERFLOW

COMP3221 lec06-numbers-II.9 Saeid Nooshabadi Signed vs. Unsigned Numbers °C declaration int Declares a signed number Uses two’s complement °C declaration unsigned int Declares a unsigned number Treats 32-bit number as unsigned integer, so most significant bit is part of the number, not a sign bit °NOTE: Hardware does all arithmetic in 2’s complement. It is up to programmer to interpret numbers as signed or unsigned. Hardware provide some information to interpret numbers as signed or unsigned (check Slides 17-20!)

COMP3221 lec06-numbers-II.10 Saeid Nooshabadi Overflow for Two’s Complement Numbers? °Adding (or subtracting) 2 32-bit numbers can yield a result that needs 33 bits sign bit set with value of result instead of proper sign of result since need just 1 extra bit, only sign bit can be wrong °When adding operands with different signs (subtracting with same signs) Overflow cannot occur OpABResult A + B>=0>=0 =0 A - B>=0 =0>=0

COMP3221 lec06-numbers-II.11 Saeid Nooshabadi Signed v. Unsigned Comparisons °X = two °Y = two °Is X > Y? unsigned: YES signed: NO °Converting to decimal to check Signed comparison: -4 ten < 1,000,000,000 ten? Unsigned comparison: 4,294,967,292 ten > 1,000,000,000 ten?

COMP3221 lec06-numbers-II.12 Saeid Nooshabadi Signed v. Unsigned Comparisons (Hardware Help) °X = two °Y = two °Is X > Y? Do the Subtraction X – Y and check result X = two – Y = two X = two + – Y = two R= two – Y in 2’s complement Result in 2’s complement -ve sign indicates X is NOT greater than Y -ve sign and carry out indicates X is greater than Y if numbers were unsigned. 1 Carry out

COMP3221 lec06-numbers-II.13 Saeid Nooshabadi Numbers are stored at addresses °Memory is a place to store bits °A word is a fixed number of bits (eg, 32) at an address also fixed no. of bits °Addresses are naturally represented as unsigned numbers = 2 k

COMP3221 lec06-numbers-II.14 Saeid Nooshabadi Status Flags in Program Status Register CPSR Copies of the ALU status flags (latched for some instructions). N = Negative result from ALU flag. Z = Zero result from ALU flag. C = ALU operation Carried out V = ALU operation oVerflowed (carry into the msb  carry out of msb) * Condition Code Flags Mode N ZCV I F T ARM Terminology: GT (Greater) X > Y (signed Arithmetic) HI (Higher)X > Y (unsigned Arithmetic)

COMP3221 lec06-numbers-II.15 Saeid Nooshabadi FlagsArithmetic Instruction NegativeBit 31 of the result has been set (N=‘1’)Indicates a negative number in signed operations ZeroResult of operation was zero (Z=‘1’) CarryResult was greater than 32 bits (C=‘1’) oVerflowResult was greater than 31 bits (V=‘1’)Indicates a possible corruption of the sign bit in signed numbers Condition Flags

COMP3221 lec06-numbers-II.16 Saeid Nooshabadi And in Conclusion... °Computers do arithmetic in 2’s complement °Interpretation of numbers can be signed or unsigned °The Arithmetic operation results should be interpreted depending the signed or unsigned interpretation of the operands.