Computer Organization COMP 210

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

HEXADECIMAL NUMBERS Code
Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.
Fabián E. Bustamante, Spring 2007 Integers Today Numeric Encodings Programming Implications Basic operations Programming Implications Next time Floats.
Chapter 8 Representing Information Digitally.
CS213 Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication.
“The course that gives CMU its Zip!” Topics Numeric Encodings –Unsigned & Two’s complement Programming Implications –C promotion rules CS 213 F’00.
“The course that gives CMU its Zip!” Topics Numeric Encodings –Unsigned & Two’s complement Programming Implications –C promotion rules Basic operations.
CS213 Integers Apr 3, 2006 Topics Numeric Encodings
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
“The course that gives CMU its Zip!” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
February 4, 2003 CSCE 212 Computer Architecture Lecture 3 Representing Integers.
Binary Representation and Computer Arithmetic
The Binary Number System
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Number Representations and Computer Arithmetic. CS 21a 9/23/02 Odds and Ends Slide 2 © Luis F. G. Sarmenta and John Paul Vergara, Ateneo de Manila University.
Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication Programming.
1 Integer Representations. 2 Outline Encodings –Unsigned and two’s complement Conversions –Signed vs. unsigned –Long vs. short Suggested reading –Chap.
Chapter 2 Bits, Data Types & Operations Integer Representation
Comp Integers Spring 2015 Topics Numeric Encodings
– 1 – CS 105 Computer Systems Introduction Topics: Staff, text, and policies Lecture topics and assignments Lab rationale CS 105 “Tour of the Black Holes.
Bits and Bytes Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C.
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication Programming.
University of Washington Integers The Hardware/Software Interface CSE351 Winter 2013.
CS 105 “Tour of the Black Holes of Computing” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
CS 105 “Tour of the Black Holes of Computing” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
Integers Topics Representations of Integers Basic properties and operations Implications for C.
Topics Numeric Encodings –Unsigned & Two’s complement Programming Implications –C promotion rules Basic operations –Addition, negation, multiplication.
– 1 – CS 105 Computer Systems Introduction Topics: Class Intro Data Representation CS 105 “Tour of the Black Holes of Computing!” Geoff Kuenning Fall 2014.
973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43, is NOT an integer (it is floating.
CHAPTER 5: Representing Numerical Data
Floating Point Numbers
CS 105 “Tour of the Black Holes of Computing!”
Negative numbers: Week 10 Lesson 1
Today’s Instructor: Randy Bryant
Integers Topics Numeric Encodings (2.2) Programming Implications
CS 367 Integers Topics (Ch. 2.2, 2.3) Numeric Encodings
Topics IEEE Floating Point Standard Rounding Floating Point Operations
CS 105 “Tour of the Black Holes of Computing!”
Bits, Bytes, and Integers CSE 238/2038/2138: Systems Programming
University of Washington
Section 2: Integer & Floating Point Numbers
Integer Representations and Arithmetic
“The course that gives CMU its Zip!”
CS213 Integers Topics Numeric Encodings Programming Implications
CS 105 “Tour of the Black Holes of Computing”
CS 105 “Tour of the Black Holes of Computing”
Data Structures Mohammed Thajeel To the second year students
C Puzzles Taken from old exams
Comp Integers Spring 2015 Topics Numeric Encodings
Computer Systems Introduction
CS 105 “Tour of the Black Holes of Computing!”
Bits, Bytes, and Integers January 16, 2008
Bits, Bytes, and Integers 2nd Lectures
Integers Topics Numeric Encodings Programming Implications
1 The Hardware/Software Interface CSE351 Spring 2011 Module 3: Integers Monday, April 4, 2011.
Representing Information (2)
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Arithmetic Topics Basic operations Programming Implications
Computer Organization COMP 210
Integer Representations Jan. 23, 2001
Computer Organization COMP 210
CS 105 “Tour of the Black Holes of Computing!”
CS213 Floating Point Topics IEEE Floating Point Standard Rounding
Computer Systems Introduction
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Presentation transcript:

Computer Organization COMP 210 Integers Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication Consequences of overflow Using shifts to perform power-of-2 multiply/divide

C Puzzles Answers on the last slide Assume machine with 32 bit word size, two’s complement integers For each of the following C expressions, either: Argue that is true for all argument values Give example where not true x < 0  ((x*2) < 0) ux >= 0 x & 7 == 7  (x<<30) < 0 ux > -1 x > y  -x < -y x * x >= 0 x > 0 && y > 0  x + y > 0 x >= 0  -x <= 0 x <= 0  -x >= 0 Initialization int x = foo(); int y = bar(); unsigned ux = x; unsigned uy = y;

Real Life Ariane 5 – European missile On June 4, 1996 an unmanned Ariane 5 rocket launched by the European Space Agency exploded just forty seconds after its lift-off from Kourou, French Guiana. first voyage, a decade of development costing $7 billion. rocket and its cargo were valued at $500 million Cause: a 64 bit floating point number relating to the horizontal velocity of the rocket with respect to the platform was converted to a 16 bit signed integer. The number was larger than 32,767, the largest integer storeable in a 16 bit signed integer, the conversion failed. See http://www-users.math.umn.edu/~arnold/disasters/ariane.html

How do we get to bits? We write programs in an abstract language like C How do we get to the binary representation? Compilers & Assemblers! We write x = 5. The compiler changes it into mov 5, 0x005F The assembler changes it into: 80483c7: 8b 45 5F Compiler figures out that this is an integer and changes it into 2’s Complement

Negative numbers Problem: how do we represent negative numbers? Sign-magnitude. Wastes space (range decreases) Not used anymore (was used on a few IBM mainframes in the dark ages) 2’s complement Space efficient Arithmetic works well

The structure of a signed integer (if we’re using sign-magnitude) This is no longer used!

Instead of using sign magnitude… We’ll break the number line in the middle

…and shift the right part of the number line to the left side to get… two’s complement …and shift the right part of the number line to the left side to get… Note that negative numbers start with a 1, but starting with a 1 is not what makes the number negative. Result is called 2’s complement. There is an easy arithmetic way to convert numbers to their negative equivalent with 2’s complement.

This is the absolute value of 110 2’s complement Rule: To find the value represented by a binary number that starts with a 1 (i.e., a negative number) Take the complement of the binary number. Add 1 to the result. determine the decimal value To find the value represented by 110 Take the Complement: 001 add 1 to the complement] + 1 find the decimal value 010 = +2 To find the value represented by a binary number that starts with a 0 (i.e., a positive number) Do nothing! This is the absolute value of 110

2’s complement range There will be more negative numbers than positive numbers since 0 takes a positive space:

The signed integers for a four-bit cell

2’s complement range Range for any cell size: Smallest number is 1000… 0 Largest number is 0111…..1 The magnitude of the smallest negative number is 1 greater than the magnitude of the largest positive number. Example: 6-bit cell: -32 to 31

Encoding Integers Unsigned Two’s Complement Sign Bit short int x = 15213; short int y = -15213; Sign Bit C short 2 bytes long Sign Bit For 2’s complement, most significant bit indicates sign 0 for nonnegative 1 for negative

Numeric Ranges Unsigned Values UMin = 0 UMax = 2w – 1 000…0 UMax = 2w – 1 111…1 Two’s Complement Values TMin = –2w–1 100…0 TMax = 2w–1 – 1 011…1 Other Values Minus 1 111…1 Values for W = 16

Values for Different Word Sizes C Programming  #include <limits.h> K&R App. B11 Declares constants, e.g.,  ULONG_MAX  LONG_MAX  LONG_MIN Values platform-specific Observations |TMin | = TMax + 1 Asymmetric range UMax = 2 * TMax + 1