Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16.

Similar presentations


Presentation on theme: "Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16."— Presentation transcript:

1 Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16

2 Announcements Quiz #1 In class Wednesday, January 16 Covers Virtual machine (levels) Computer languages (levels) General architecture (CISC) VonNeumann architecture (stored program) Instruction Execution Cycle CPU, ALU, registers, buses, etc Internal/external representation Signed/unsigned integer IEEE floating-point Binary, decimal, hexadecimal Parity Characters (table provided) Integer arithmetic

3 Today’s topics More internal representation More internal representation Signed/unsigned integers Signed/unsigned integers External representation External representation Binary, decimal, hexadecimal number systems Binary, decimal, hexadecimal number systems Binary arithmetic Binary arithmetic Floating-point representation Floating-point representation Error-detecting and error-correcting codes Error-detecting and error-correcting codes

4 Other representations Every integer number has a unique representation in each "base"  2 Every integer number has a unique representation in each "base"  2 Hexadecimal is commonly used for easily converting binary to a more manageable form. Hexadecimal is commonly used for easily converting binary to a more manageable form. example 16-bit binary  hexadecimal: example 16-bit binary  hexadecimal: Binary 0001 0111 1011 1101 Hexadecimal 1 7 B D Write it as 0x17BD or 17BDh

5

6 Converting decimal  hexadecimal Use same methods as decimal  binary Use same methods as decimal  binary The only difference is the place values The only difference is the place values Example decimal  hexadecimal Example decimal  hexadecimal 157 decimal = 9D hex(0x9D or 9Dh) … or convert to binary, then to hex … or convert to binary, then to hex

7 Negative hex (signed integers) How can you tell if a hexadecimal representation of a signed integer is negative? How can you tell if a hexadecimal representation of a signed integer is negative? Recall that a 16-bit signed integer is negative if the leftmost bit is 1 Recall that a 16-bit signed integer is negative if the leftmost bit is 1 16-bit (4 hex digits) examples: 16-bit (4 hex digits) examples: 0x7a3e is positive 0x7a3e is positive 0x8a3e is negative 0x8a3e is negative 0xFFFF is negative 0xFFFF is negative

8 Character and control codes Letters, digits, special characters … are represented internally as numbers Letters, digits, special characters … are represented internally as numbers ASCII256 codes (1-byte) ASCII256 codes (1-byte) e.g., 'A' … 'Z' are codes 65 - 90 e.g., 'A' … 'Z' are codes 65 - 90 e.g., '0' … '9' are codes 48 - 57 e.g., '0' … '9' are codes 48 - 57 Unicode65,536 codes (2-byte) Unicode65,536 codes (2-byte) Some codes are used for controlling devices Some codes are used for controlling devices e.g., code 10 is “new line” for output device e.g., code 10 is “new line” for output device e.g., code 27 is “escape” e.g., code 27 is “escape” Device controllers translate codes (device- dependent) Device controllers translate codes (device- dependent) All keyboard input is character (including digits) All keyboard input is character (including digits)

9 Digits Digits entered from the keyboard are characters Digits entered from the keyboard are characters E.G., ‘0’ is character number 48, … ‘9’ is character number 57 E.G., ‘0’ is character number 48, … ‘9’ is character number 57 What happens if we add ‘3’ + ‘5’? What happens if we add ‘3’ + ‘5’? The answer is ‘h’ The answer is ‘h’ Numeric data types require conversion by the input/output operations Numeric data types require conversion by the input/output operations

10

11 Neutral representation Inside the computer Inside the computer Bytes, words, etc., can represent some finite number of combinations of off/on switches. Bytes, words, etc., can represent some finite number of combinations of off/on switches. Each distinct combination is called a code. Each distinct combination is called a code. Each code can be used to represent: Each code can be used to represent: numeric value numeric value memory address memory address machine instruction machine instruction keyboard character keyboard character Representation is neutral. The operating system and the programs decide how to interpret the codes. Representation is neutral. The operating system and the programs decide how to interpret the codes.

12 Arithmetic operations The following examples use 8-bit twos- complement operands The following examples use 8-bit twos- complement operands Everything extends to 16-bit, 32-bit, n-bit representations. Everything extends to 16-bit, 32-bit, n-bit representations. What is the range of values for 8-bit operands? What is the range of values for 8-bit operands? The usual arithmetic operations can be performed directly in binary form with n-bit representations. The usual arithmetic operations can be performed directly in binary form with n-bit representations.

13 Addition Specify result size (bits) Specify result size (bits) Use the usual rules of add and carry Use the usual rules of add and carry With two operands, the carry bit is never greater than one With two operands, the carry bit is never greater than one 0+0+1 = 1,0+1+1 = 10,1+0+1 = 10,1+1+1 = 11 0+0+1 = 1,0+1+1 = 10,1+0+1 = 10,1+1+1 = 11 Example: Example:00101101 +00011110 01001011 How does overflow occur? How does overflow occur?

14 Subtraction Use the usual rules Use the usual rules Order matters Order matters Borrow and subtract Borrow and subtract Example: Example: … or negate and add … or negate and add Example: Example: How does underflow occur? How does underflow occur?

15 Verification Perform operation on binary operands Perform operation on binary operands Convert result to decimal Convert result to decimal Convert operands to decimal Convert operands to decimal Perform operation on decimal operands Perform operation on decimal operands [Convert result to binary] [Convert result to binary] Compare results Compare results

16 Multiplication Usual algorithm Usual algorithm Repeated addition Repeated addition … or shift left (and adjust if multiplier is not a power of 2) … or shift left (and adjust if multiplier is not a power of 2) Check for overflow Check for overflow

17 Division Usual algorithm Usual algorithm Repeated subtraction Repeated subtraction … or shift right (if divisor is a power of 2) … or shift right (if divisor is a power of 2) too complicated if divisor is not a power of 2 too complicated if divisor is not a power of 2 Check underflow for remainder Check underflow for remainder

18 Arithmetic operations Note: all of the arithmetic operations can be accomplished using only Note: all of the arithmetic operations can be accomplished using only add add complement complement

19 Floating-point representation “decimal” means “base ten” “decimal” means “base ten” “floating-point” means “a number with an integral part and a fractional part “floating-point” means “a number with an integral part and a fractional part Sometimes call “real”, “float” Sometimes call “real”, “float” Generic term for “decimal point” is “radix point” Generic term for “decimal point” is “radix point”

20 Converting floating-point (decimal  binary) Place values: Place values: 25252525 24242424 23232323 22222222 21212121 20202020 2 -1 2 -2 2 -3 2 -4 2 -5 321684210.50.250.1250.06250.03125 Integral partFractional part Example: 4.5 (decimal) = 100.1 (binary)

21 Converting floating-point (decimal  binary) Example:6.25 = 110.01 Example:6.25 = 110.01 Method: Method: 6 = 110(Integral part: convert in the usual way).25 x 2 = 0.5(Fractional part: successive multiplication by 2).5 x 2 = 1.0(Stop when fractional part is 0) 110.01 110.01 Example:6.2  110.001100110011… Example:6.2  110.001100110011… 6 = 110.2 x 2 = 0.4.4 x 2 = 0.8.8 x 2 = 1.6.6 x 2 = 1.2.2 x 2 = 0.4(repeats) 110.0011 0011 0011 110.0011 0011 0011

22 Internal representation of floating- point numbers Some architectures handle the integer part and the fraction part separately Some architectures handle the integer part and the fraction part separately Slow Slow Most use a completely different representation and a different ALU (IEEE standard) Most use a completely different representation and a different ALU (IEEE standard) Range of values for 32-bit Range of values for 32-bit Approximately -3.4 x 10 38 … +3.4 x 10 38 Approximately -3.4 x 10 38 … +3.4 x 10 38 Limited precision Limited precision Approximately -1.4 x 10 -45 … +1.4 x 10 -45 Approximately -1.4 x 10 -45 … +1.4 x 10 -45

23 IEEE 754 standard single-precision (32-bit) single-precision (32-bit) double-precision (64-bit) double-precision (64-bit) extended (80-bit) extended (80-bit) 3 parts 3 parts 1 sign bit 1 sign bit "biased" exponent (single: 8 bits, "biased" exponent (single: 8 bits, double: 11 bits double: 11 bits extended: 15 bits) extended: 15 bits) "normalized" mantissa (single: 23 bits, "normalized" mantissa (single: 23 bits, double: 52 bits double: 52 bits extended: 64 bits) extended: 64 bits)

24 Examples: 6.25 in IEEE single precision is 6.25 in IEEE single precision is 0 10000001 10010000000000000000000 40C80000 hexadecimal 6.2 in IEEE is 6.2 in IEEE is 0 10000001 10001100110011001100110 40C66666 hexadecimal SignBiased exponentNormalized mantissa

25 Examples: 6.25 in IEEE single precision 6.25 in IEEE single precision 6.25 (decimal) = 110.01 (binary) Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 = 1.1001 x 2 2 = 1.1001 x 2 2 … so the sign bit is 0 (positive) … the “biased” exponent is 2 + 127 = 129 = 10000001 … and the “normalized” mantissa is 1001 (drop the 1, and zero-fill). 0 10000001 10010000000000000000000 40C80000 hexadecimal

26 Examples: 6.2 in IEEE is 6.2 in IEEE is 6.2 (decimal) = 110.001100110011… (binary) Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 = 1.10001100110011… x 2 2 = 1.10001100110011… x 2 2 … so the sign bit is 0 (positive) … the “biased” exponent is 2 + 127 = 129= 10000001 10001100110011… … and the “normalized” mantissa is 10001100110011… (drop the 1). 0 10000001 10001100110011001100110 40C66666 hexadecimal

27 What decimal floating-point number is represented by C1870000H? What decimal floating-point number is represented by C1870000H? 1100 0001 1000 0111 0000 0000 0000 0000 … so the sign is negative … the “unbiased” exponent is 131 - 127 = 4 00001110000000000000000 … and the “unnormalized” mantissa is 1.00001110000000000000000 (add the 1 left of the radix point). Move the radix point 4 places to the right:10000.111 = -16.875 -10000.111 = -16.875 Example: SignBiased exponent Normalized mantissa

28 Internal representation Regardless of external representation, all I/O eventually is converted into electrical (binary) codes. Regardless of external representation, all I/O eventually is converted into electrical (binary) codes. Inside the computer, everything is represented by gates (open/closed). Inside the computer, everything is represented by gates (open/closed).

29 Problem with Internal Representation Since the number of gates in each group (byte, word, etc.) is finite, computers can represent numbers with finite precision only. Since the number of gates in each group (byte, word, etc.) is finite, computers can represent numbers with finite precision only. Examples: Examples: Suppose that signed integer data is represented using 16 bits. The largest integer that can be represented is 65535. What happens if we add 1 ? Suppose that signed integer data is represented using 16 bits. The largest integer that can be represented is 65535. What happens if we add 1 ? 0 0 What happens when we need to represent 1/3 ? What happens when we need to represent 1/3 ? Representations may be truncated; overflow / underflow can occur, and the Status Register will be set Representations may be truncated; overflow / underflow can occur, and the Status Register will be set Limited precision for floating-point representations Limited precision for floating-point representations

30 Looking inside … 11010110What does this code represent? 11010110What does this code represent? Number ? Number ? 8-bit unsigned 214 ? 8-bit unsigned 214 ? 8-bit signed - 42 ? 8-bit signed - 42 ? partial 16-bit integer ? partial 16-bit integer ? partial floating point ? partial floating point ? Character ? Character ? ASCII ‘ ╓ ’ ? ASCII ‘ ╓ ’ ? partial Unicode ‘Ö’ partial Unicode ‘Ö’ Address ? Address ? Instruction ? Instruction ? Garbage ? Garbage ?

31 Neutral representation Inside the computer Inside the computer Bytes, words, etc., can represent a finite number of combinations of off/on switches. Bytes, words, etc., can represent a finite number of combinations of off/on switches. Each distinct combination is called a code. Each distinct combination is called a code. Each code can be used to represent: Each code can be used to represent: numeric value numeric value memory address memory address machine instruction machine instruction keyboard character keyboard character Representation is neutral. The operating system and the programs decide how to interpret the codes. Representation is neutral. The operating system and the programs decide how to interpret the codes.

32 Simple Error Checking Each computer architecture is designed to use either even parity or odd parity Each computer architecture is designed to use either even parity or odd parity System adds a parity bit to make each code match the system's parity System adds a parity bit to make each code match the system's parity Parity is the total number of '1' bits (including the extra parity bit) in a binary code Parity is the total number of '1' bits (including the extra parity bit) in a binary code

33 Parity (error checking) Example parity bits for 8-bit code 11010110 Example parity bits for 8-bit code 11010110 Even-parity system:111010110(sets parity bit to 1 to make a total of 6 one-bits) Even-parity system:111010110(sets parity bit to 1 to make a total of 6 one-bits) Odd-parity system:011010110(sets parity bit to 0 to keep 5 one-bits) Odd-parity system:011010110(sets parity bit to 0 to keep 5 one-bits) Code is checked for parity error whenever it is used. Code is checked for parity error whenever it is used. Examples for even-parity architecture: Examples for even-parity architecture: 101010101error (5 one-bits) 101010101error (5 one-bits) 100101010OK (4 one-bits) 100101010OK (4 one-bits) Examples for odd-parity architecture: Examples for odd-parity architecture: 101010101OK (5 one-bits) 101010101OK (5 one-bits) 100101010error (4 one-bits) 100101010error (4 one-bits)

34 Parity (error checking) Used for checking memory, network transmissions, etc. Used for checking memory, network transmissions, etc. Error detection Error detection Not 100% reliable. Not 100% reliable. Works only when error is in odd number of bits Works only when error is in odd number of bits … but very good because most errors are single-bit … but very good because most errors are single-bit Next time … Next time … Error-correcting codes (ECC) Error-correcting codes (ECC)

35 Questions? Do Homework #1 Quiz #1 Wednesday


Download ppt "Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16."

Similar presentations


Ads by Google