Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Similar documents
CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

COMP2611: Computer Organization. Data Representation

Numeric Encodings Prof. James L. Frankel Harvard University

Inf2C - Computer Systems Lecture 2 Data Representation

M1 Computers and Data

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Introduction to Computers and Programming. Numeric Values

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

IEEE Standard for Floating-Point Arithmetic: 754

Floating Point Arithmetic

CO212 Lecture 10: Arithmetic & Logical Unit

COMP Overview of Tutorial #2

Computer Architecture Review. Jo, Heeseung

Thomas Polzer Institut für Technische Informatik

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Data Representation 1

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Floating Point Arithmetic

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

System Programming CISC 360. Floating Point September 16, 2008

Floating Point Numbers

Chapter 3. Arithmetic Text: P&H rev

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Chapter Three. Arithmetic

ECE232: Hardware Organization and Design

Foundations of Computer Systems

15213 Recitation 2: Floating Point

CHAPTER 1 Numerical Representation

Floating Point January 24, 2008

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

ECE331: Hardware Organization and Design

Integer Representation

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Representing and Manipulating Floating Points. Jo, Heeseung

Chapter 4: Data Representations

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

LAB A Translating Data to Binary

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Chapter 3. Arithmetic for Computers

Integers and Floating Point

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Floating-point representations

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

Floating-point representations

CS 101: Computer Programming and Utilization

Binary Representations and Arithmetic

CS101 Lecture 04: Binary Arithmetic

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

Giving credit where credit is due

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

Giving credit where credit is due

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number Systems. Both numbers are positive

FLOATING POINT NUMBERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Final Labs and Tutors

Chapter 3: Arithmetic for Computers

CPE300: Digital System Architecture and Design

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Divide: Paper & Pencil

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

The Design of C: A Rational Reconstruction

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

Beginning C Programming for Engineers

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

UNIT 7A Data Representation: Numbers and Text. Digital Data

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Computer Organization: A Programmer's Perspective

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

COMPUTER ORGANIZATION AND DESIGN

EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

Organisasi Sistem Komputer

Computer Systems C S Cynthia Lee

Transcription:

CSE 2021: Computer Organization Recap from Last Time load from disk High-Level Program Lecture-2(a) Data Translation Binary patterns, signed and unsigned integers Today s topic Data Translation Code Translation compiler Assembly Lang (obj) Shakil M. Khan (adapted from Prof. Roumani) Machine Lang (exe) save.exe to disk CSE-2021 May-12-2011 2 Data Translation It s all about numbers! mapping text, pictures, sound, to numbers The binary world binary patterns, bits and bytes, hex, the 2 n rule Unsigned Integers the binary system, shift/mod, converting to/from Signed Integers sign and magnitude, one s/two s complement, converting, add/sub, sign extension Real Numbers IEEE-754, single and double precisions It s All about Numbers! Text Pictures Video clips Audio CSE-2021 May-12-2011 3 CSE-2021 May-12-2011 4 1

The Binary World Bit Numbering Binary digits (bits) 0 or 1 ON or OFF high or low (voltage) Binary patterns strings of bits e.g.: 10 0100 0101 0000 0001 1111 1101 0101 Representation size 1 byte = 8 bits 1 word = 4 bytes = 32 bits 0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 31 30 29 3 2 1 0 Least Significant bit (LSb) = bit #0 Most Significant bit (MSb) = bit #31 Least Significant Byte (LSB) Most Significant Byte (MSB) CSE-2021 May-12-2011 5 CSE-2021 May-12-2011 6 The 2 n Rule (1) n bits can represent 2 n distinct numbers Examples: 2 1 => {0,1} 2 2 => {00,01,10,11} 2 3 => {000,001,010,011,100,101,110,111} 2 4 => {0000,0001,0010,0011,0100,0101,0110,0111, 1000,1001,1010,1011,1100,1101,1110,1111} The 2 n Rule (2) The largest natural number that can be represented by n bits = 2 n -1 Examples: 1 bit => 1 2 bits => 3 3 bits => 7 4 bits => 15 CSE-2021 May-12-2011 7 CSE-2021 May-12-2011 8 2

Binary Patterns (Exercises) Unsigned Integers (1) Prove that a binary pattern of size n can represent any one of 2 n different things (hint: use induction) We want to represent a signal that has 41 possible values. How many bits do we need? How many bytes are needed to store a 640 x 320 coloured picture using 16 colour shade for each of Red, Green, and Blue? The binary system the value of i th digit d = d x 2 i Converting to decimal 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 31 30 29 3 2 1 0 = 0x2 31 +0x2 30 +0x2 29 +1x2 28 + +0x2 2 +1x2 1 +1x2 0 = 0 + 0 + 0 + 268435456 + + 0 + 2 + 1 = 268435459 10 CSE-2021 May-12-2011 9 CSE-2021 May-12-2011 10 Unsigned Integers (2) Range/word: 0 to +4,294,967,295 (in binary: 00...000 to 11...111) Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Unsigned Integers (3) Converting from decimal the mod e.g. convert 6 10 to binary convert 101 10 to binary Range: 0 to +2 n 1 CSE-2021 May-12-2011 11 CSE-2021 May-12-2011 12 3

Logical Shifts Other Bitwise Operations Logical shifts Left shift Z by n bits =Z x 2 n Right shift Z by n bits =Z / 2 n X Y and or 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 Shift Left Logical 000000 CSE-2021 May-12-2011 13 xor not (X) 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 nand, nor,... CSE-2021 May-12-2011 14 The Hex Notation Unsigned Integers (Exercises) Read/write long binary strings: tedious Solution use higher base data size of all computers today = multiples of 4 Use hexadecimal numbers why not decimal? 16 = 2 4, so convert 4 bits at a time using lookup table often written with prefix `0x Examples? bits 0000 0001 0010 0011 0100 0101 0110 0111 hex 0 1 2 3 4 5 6 7 bits 1000 1001 1010 1011 1100 1101 1110 1111 hex 8 9 A B C D E F Represent the unsigned integer 75 Determine the decimal value of the unsigned integer 0x4A Given an unsigned integer k, how many bits are needed to represent it? Compute largest unsigned integer that can fit in one, two, four, and eight bytes are your answers consistent with the 2 n rule? Consider the bit pattern 0xAFC7 and imagine shifting all its bits left by one position. Show that it becomes 0x5F8E CSE-2021 May-12-2011 15 CSE-2021 May-12-2011 16 4

More Exercises How many bytes are needed to store a 640 x 320 coloured picture using 16 colour shades for each of Red, Green, and Blue? As above but for a one-min silent video clip with 24 fps and the same specs as above? As above but add 16-bit sound sampled at 40 khz? Signed Integers Signed integers sign and magnitude the 1 s complement the 2 s complement Converting to decimal from decimal Arithmetic right shifts Sign vs. zero extension CSE-2021 May-12-2011 17 CSE-2021 May-12-2011 18 Sign and Magnitude Range/word: -2,147,483,647 to +2,147,483,647 (in binary: 11...111 to 01...111) Format reserve 1 bit for sign rest for magnitude Issues where to put the sign bit? both positive and negative zeros 00...000 and 10...000 complex h/w: needs extra step to set sign bit The 1 s Complement Range/word: -2,147,483,647 to +2,147,483,647 (in binary: 10...000 to 01...111) Format positive as unsigned (but MSb not used: why?) invert all bits for negative Issues again, positive and negative zeros 00...000 and 11...111 complex h/w: needs extra step to subtract CSE-2021 May-12-2011 19 CSE-2021 May-12-2011 20 5

The 2 s Complement (1) Used universally since 1965 Range/word: -2,147,483,648 to +2,147,483,647 (in binary: 10...000 to 01...111) Advantages non-negative numbers have the same unsigned and 2scomplement representation all negative numbers have 1 in MSb, so h/w needs to check sign bit only for polarity The 2 s Complement (2) Issues positive and negative numbers not balanced Some specific numbers 0: 0000 0000 0000 1: 1111 1111 1111 Most-negative: 1000 0000 0000 Most-positive: 0111 1111 1111 CSE-2021 May-12-2011 21 CSE-2021 May-12-2011 22 The 2 s Complement (3) Given an n-bit number x = -x n-1 2 n-1 + x n-2 2 n-2 +... + x 1 2 1 + x 0 2 0 Range: 2 n 1 to +2 n 1 1 Example 1111 1111 1111 1111 1111 1111 1111 1100 2 = 1 2 31 + 1 2 30 + + 1 2 2 +0 2 1 +0 2 0 = 2,147,483,648 + 2,147,483,644 = 410 Signed Negation Complement and add 1 Example: negate +2 +2 = 0000 0000 0010 2 2 = 1111 1111 1101 2 + 1 = 1111 1111 1110 2 More examples CSE-2021 May-12-2011 23 CSE-2021 May-12-2011 24 6

Signed integers : add or sub? Arithmetic Right Shift Compute 0x4E + 0xA3 0x4E = 0 1 0 0 1 1 1 0 78 +78 0xA3 = 1 0 1 0 0 0 1 1 163-93 0xF1 = 1 1 1 1 0 0 0 1 241-15 Try right shifting a signed negative number 0xFFFF FFFE >> 1 = 0x7FFF FFFF -1 shifted right once = large positive number!! Solution arithmetic right shift What about left shifting signed numbers? CSE-2021 May-12-2011 25 CSE-2021 May-12-2011 26 Sign Extension Representing a number using more bits preserve the numeric value Many instructions have 16-bit operands need to extend to 32 bits Replicate the sign bit to the left contrast with zero extension (for unsigned ints) Examples: 8-bit to 16-bit +2: 0000 0010 => 0000 0000 0000 0010 2: 1111 1110 => 1111 1111 1111 1110 Signed Integers (Exercises) Represent the signed integer -75 Determine the decimal value of the signed integer 0x4A Why does sign extension work? Compute smallest and largest signed integer that can fit in one, two, four, and eight bytes. are your answers consistent with 2 n? CSE-2021 May-12-2011 27 CSE-2021 May-12-2011 28 7

Labs Office Hours Labs start next week PreLab + exercise PreLab can submit from home unsubmit folder Exercise (LabTest mode) submit as many times as you want submitting = OK or reveals failed test case (no penalty) automatic 5/5 (manual 0/5-4/5) Makeup A-D + K-N Office hours TA (right before the lab) + forum (every Friday) change my office hours (or call me @ x33928, I can let you in)??? CSE-2021 May-12-2011 29 CSE-2021 May-12-2011 30 CSE 2021: Computer Organization Lecture-2(b) Data Translation Floating point representation (IEEE 754) Shakil M. Khan Floating Point Representation for non-integral numbers including very small and very large numbers Like scientific notation 2.34 10 56 normalized +0.002 10 4 +987.02 10 9 not normalized In binary ±1.xxxxxxx 2 2 yyyy Types float and double in C CSE-2021 May-12-2011 32 8

Floating Point Standard Defined by IEEE Std 754-1985 Developed in response to divergence of representations portability issues for scientific code Now almost universally adopted Two representations single precision (32-bit) double precision (64-bit) CSE-2021 May-12-2011 33 IEEE Floating-Point Format single: 8 bits double: 11 bits single: 23 bits double: 52 bits S Exponent Fraction S x ( 1) (1 Fraction) 2 (Exponent Bias) S: sign bit (0 non-negative, 1 negative) Normalize significand: 1.0 significand < 2.0 always has a leading pre-binary-point 1 bit, so no need to represent it explicitly (hidden bit) significand is fraction with the 1. restored Exponent: excess representation: actual exponent + Bias ensures exponent is unsigned single: bias = 127; double: bias = 1203 CSE-2021 May-12-2011 34 Single-Precision Range Exponents 00000000 and 11111111 reserved Smallest value Exponent: 00000001 actual exponent = 1 127 = 126 Fraction: 000 00 significand = 1.0 ±1.0 2 126 ±1.2 10 38 Largest value exponent: 11111110 actual exponent = 254 127 = +127 Fraction: 111 11 significand 2.0 ±2.0 2 +127 ±3.4 10 +38 Double-Precision Range Exponents 0000 00 and 1111 11 reserved Smallest value Exponent: 00000000001 actual exponent = 1 1023 = 1022 Fraction: 000 00 significand = 1.0 ±1.0 2 1022 ±2.2 10 308 Largest value Exponent: 11111111110 actual exponent = 2046 1023 = +1023 Fraction: 111 11 significand 2.0 ±2.0 2 +1023 ±1.8 10 +308 CSE-2021 May-12-2011 35 CSE-2021 May-12-2011 36 9

Floating-Point Precision Relative precision all fraction bits are significant Single: approx 2 23 equivalent to 23 log 10 2 23 0.3 6 decimal digits of precision Double: approx 2 52 equivalent to 52 log 10 2 52 0.3 16 decimal digits of precision Floating-Point Example Represent 0.75 0.75 = ( 1) 1 1.1 2 2 1 S = 1 Fraction = 1000 00 2 Exponent = 1 + Bias Single: 1 + 127 = 126 = 01111110 2 Double: 1 + 1023 = 1022 = 01111111110 2 Single: 1011111101000 00 Double: 1011111111101000 00 CSE-2021 May-12-2011 37 CSE-2021 May-12-2011 38 Floating-Point Example What number is represented by the singleprecision float 11000000101000 00 S = 1 Fraction = 01000 00 2 Exponent = 10000001 2 = 129 x = ( 1) 1 (1 + 01 2 ) 2 (129 127) = ( 1) 1.25 2 2 = 5.0 Infinities and NaNs Exponent = 111...1, Fraction = 000...0 ±Infinity can be used in subsequent calculations, avoiding need for overflow check Exponent = 111...1, Fraction 000...0 Not-a-Number (NaN) indicates illegal or undefined result e.g., 0.0 / 0.0 can be used in subsequent calculations CSE-2021 May-12-2011 39 CSE-2021 May-12-2011 40 10

Floating-Point (Exercises) Convert to IEEE-754-210.25 10 How about 1.36 10 can only approximate Try -0.085 10 CSE-2021 May-12-2011 41 11