Data Representation Binary Numbers Binary Addition

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

ICS312 Set 2 Representation of Numbers and Characters.
Data Representation Computer Organization &
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java

Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Data Representation ICS 233
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Binary Number Systems.
Binary Representation and Computer Arithmetic
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for.
Simple Data Type Representation and conversion of numbers
Computers Organization & Assembly Language
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
Computer Science 111 Fundamentals of Programming I Number Systems.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ICS312 Set 1 Representation of Numbers and Characters.
Assembly Language for x86 Processors 7 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this.
CPU Internal memory I/O interface circuit System bus
CSC 221 Computer Organization and Assembly Language
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Computer Organization and Assembly Languages 2007/11/10
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
MATH Lesson 2 Binary arithmetic.
Floating Point Numbers
CS2100 Computer Organisation
Data Representation COE 308 Computer Architecture
Programming and Data Structure
Data Representation ICS 233
Lec 3: Data Representation
Assembly Language for x86 Processors 6th Edition
Data Representation.
Number Representation
Assembly Language (CSW 353)
Integer Real Numbers Character Boolean Memory Address CPU Data Types
ECE 103 Engineering Programming Chapter 3 Numbers
William Stallings Computer Organization and Architecture 7th Edition
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Data Representation COE 301 Computer Organization
Number Representations
Fundamentals of Programming I Number Systems
Data Representation in Computer Systems
ECEG-3202 Computer Architecture and Organization
Computer Organization and Assembly Language
Chapter 8 Computer Arithmetic
Data Representation ICS 233
Computer Organization and Assembly Language
Number Representations
Data Representation COE 308 Computer Architecture
Presentation transcript:

Data Representation Binary Numbers Binary Addition Translating between binary and decimal Binary Addition Integer Storage Sizes Hexadecimal Integers Translating between decimal and hexadecimal Hexadecimal subtraction Signed Integers Binary subtraction Character Storage Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Binary Numbers Digits are 1 and 0 MSB – most significant bit 1 = true 0 = false MSB – most significant bit LSB – least significant bit Bit numbering: Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Binary Numbers Every binary number is a sum of powers of 2 Each digit (bit) is either 1 or 0 Each bit represents a power of 2: Every binary number is a sum of powers of 2 Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Translating Binary to Decimal Weighted positional notation shows how to calculate the decimal value of each binary bit: dec = (Dn-1  2n-1) + (Dn-2  2n-2) + ... + (D1  21) + (D0  20) D = binary digit binary 00001001 = decimal 9: (1  23) + (1  20) = 9 Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Translating Unsigned Decimal to Binary Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the translated value: (see Decimal-to-binary.pdf for further explanation!) 37 = 100101 Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015. (Modified – John Carelli)

Binary Addition Starting with the LSB, add each pair of digits, include the carry if present. Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Integer Storage Sizes Standard sizes: What is the largest unsigned integer that may be stored in 20 bits? Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Hexadecimal Integers Binary values are represented in hexadecimal. Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Translating Binary to Hexadecimal Each hexadecimal digit corresponds to 4 binary bits. Example: Translate the binary integer 000101101010011110010100 to hexadecimal: Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Converting Hexadecimal to Decimal Multiply each digit by its corresponding power of 16: dec = (D3  163) + (D2  162) + (D1  161) + (D0  160) Hex 1234 equals (1  163) + (2  162) + (3  161) + (4  160), or decimal 4,660. Hex 3BA4 equals (3  163) + (11 * 162) + (10  161) + (4  160), or decimal 15,268. Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Powers of 16 Used when calculating hexadecimal values up to 8 digits long: Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Converting Decimal to Hexadecimal decimal 422 = 1A6 hexadecimal Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Hexadecimal Addition 36 28 28 6A 42 45 58 4B 78 6D 80 B5 Divide the sum of two digits by the number base (16). The quotient becomes the carry value, and the remainder is the sum digit. 1 1 36 28 28 6A 42 45 58 4B 78 6D 80 B5 21 / 16 = 1, rem 5 Important skill: Programmers frequently add and subtract the addresses of variables and instructions. Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Hexadecimal Subtraction When a borrow is required from the digit to the left, add 16 (decimal) to the current digit's value: 16 + 5 = 21 -1 C6 75 A2 47 24 2E Practice: The address of var1 is 00400020. The address of the next variable after var1 is 0040006A. How many bytes are used by var1? Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

What about negative numbers? Signed Binary Most intuitive approach Use the MSB to represent the sign MSB -> most significant bit 0 is positive, 1 is negative “complement” notation One’s-complement Two’s-complement First look at Signed Binary

Signed Integers Binary: The highest bit indicates the sign. 1 = negative, 0 = positive F 6 A Hexadecimal: If the highest digit of an integer is > 7 (i.e. highest bit is 1), the value is negative. Above examples: F6 is negative, 0A is positive Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015. (modified John Carelli)

Signed Binary Addition and Subtraction get complicated 2+3 2-3 2+ (-3) Need to identify the sign of each operand to decide whether to add or subtract 2+3 2-3 2+ (-3) (-2) + 3 (-2) – (-3)

Two’s Complement Notation Negative representation of number is selected such that, when it is added to the positive number, the result is zero. To construct the two’s complement : First, create a one’s complement representation by inverting each bit Then add one to the resulting one’s complement value

Forming the Two's Complement Negative numbers are stored in two's complement notation Represents the additive Inverse Note that 00000001 + 11111111 = 00000000 Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Why two’s complement? Subtraction happens automatically when positive and negative numbers are added It eliminates the need for a subtraction circuit Example: 3 – 6 is the same as 3 + (-6) 3: 0011 + (-6): 1010 (-3): 1101 3: 0011 6: 0110 -3: 1101 -6: 1010

Binary Subtraction When subtracting A – B, convert B to its two's complement, then add… Add A to (–B) 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 – 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 0 0 1 Practice: Subtract 0101 from 1001. Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Two’s Complement Examples 3 Bits Unsigned Two’s Complement 011 3  010 2  001 1  000 0  111 7  −1  110 6  −2  101 5  −3  100 4  −4 8 Bits Unsigned Two’s Complement 0111 1111 127  0111 1110 126  0000 0010 2  0000 0001 1  0000 0000 0  1111 1111 255  −1  1111 1110 254  −2  1000 0010 130  −126  Source: Wikipedia

Ranges of Signed Integers The highest bit is reserved for the sign. This limits the range: Practice: What is the largest positive value that may be stored in 20 bits? Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

What about fractions? No new operations, just like integer arithmetic Line up the decimal points Decimal example: 40.625 40625 -1.25 -1250 39.375 39375 10-1 10-2 10-3

More on fractions Fixed-point arithmetic + 11111110.110 (-1.25) Use a “binary point” instead of a “decimal” point Be sure to line them up! Addition/subtraction, two’s complement work as with integers 00101000.101 (40.625) + 11111110.110 (-1.25) 00100111.011 (39.375) 2-1 = 0.5 2-2 = 0.25 2-3 = 0.125

F x 2E Floating Point Use “scientific notation” with a base of 2: F is the fraction E is the exponent Stored in binary “word” with a standardized format Define by IEEE (Standard 754-1985) Single precision (32 bits) 1 sign bit 8 exponent bits 23 fraction bits

IEEE Floating-Point Binary Reals Types Single Precision 32 bits: 1 bit for the sign, 8 bits for the exponent, and 23 bits for the fractional part of the significand. Approximately 7 decimal digits of precision Range of approximately 10+/-38 Double Precision 64 bits: 1 bit for the sign, 11 bits for the exponent, and 52 bits for the fractional part of the significand. Approximately 15 decimal digits of precision Range of approximately 10+/-308 Double Extended Precision 80 bits: 1 bit for the sign, 16 bits for the exponent, and 63 bits for the fractional part of the significand. Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015. modified John Carelli

Character Storage Character sets Null-terminated String Standard ASCII (0 – 127) Extended ASCII (0 – 255) ANSI (0 – 255) Unicode (0 – 65,535) Null-terminated String Array of characters followed by a null byte Using the ASCII table back inside cover of book Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.

Ascii Table

Numeric Data Representation pure binary can be calculated directly ASCII binary string of digits: "01010101" ASCII decimal string of digits: "65" ASCII hexadecimal string of digits: "9C" next: Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 7/e, 2015.