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
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
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
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 Hexadecimal 1 7 B D Write it as 0x17BD or 17BDh
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
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
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 e.g., 'A' … 'Z' are codes e.g., '0' … '9' are codes e.g., '0' … '9' are codes 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)
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
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.
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.
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 = 1,0+1+1 = 10,1+0+1 = 10,1+1+1 = = 1,0+1+1 = 10,1+0+1 = 10,1+1+1 = 11 Example: Example: How does overflow occur? How does overflow occur?
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?
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
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
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
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
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”
Converting floating-point (decimal binary) Place values: Place values: Integral partFractional part Example: 4.5 (decimal) = (binary)
Converting floating-point (decimal binary) Example:6.25 = Example:6.25 = 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) Example:6.2 … Example:6.2 … 6 = x 2 = x 2 = x 2 = x 2 = x 2 = 0.4(repeats)
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 … +3.4 x Approximately -3.4 x … +3.4 x Limited precision Limited precision Approximately -1.4 x … +1.4 x Approximately -1.4 x … +1.4 x
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)
Examples: 6.25 in IEEE single precision is 6.25 in IEEE single precision is C80000 hexadecimal 6.2 in IEEE is 6.2 in IEEE is C66666 hexadecimal SignBiased exponentNormalized mantissa
Examples: 6.25 in IEEE single precision 6.25 in IEEE single precision 6.25 (decimal) = (binary) Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 = x 2 2 = x 2 2 … so the sign bit is 0 (positive) … the “biased” exponent is = 129 = … and the “normalized” mantissa is 1001 (drop the 1, and zero-fill) C80000 hexadecimal
Examples: 6.2 in IEEE is 6.2 in IEEE is 6.2 (decimal) = … (binary) Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 = … x 2 2 = … x 2 2 … so the sign bit is 0 (positive) … the “biased” exponent is = 129= … … and the “normalized” mantissa is … (drop the 1) C66666 hexadecimal
What decimal floating-point number is represented by C H? What decimal floating-point number is represented by C H? … so the sign is negative … the “unbiased” exponent is = … and the “unnormalized” mantissa is (add the 1 left of the radix point). Move the radix point 4 places to the right: = = Example: SignBiased exponent Normalized mantissa
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).
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 What happens if we add 1 ? Suppose that signed integer data is represented using 16 bits. The largest integer that can be represented is 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
Looking inside … What does this code represent? What 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 ?
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.
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
Parity (error checking) Example parity bits for 8-bit code Example parity bits for 8-bit code Even-parity system: (sets parity bit to 1 to make a total of 6 one-bits) Even-parity system: (sets parity bit to 1 to make a total of 6 one-bits) Odd-parity system: (sets parity bit to 0 to keep 5 one-bits) Odd-parity system: (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: error (5 one-bits) error (5 one-bits) OK (4 one-bits) OK (4 one-bits) Examples for odd-parity architecture: Examples for odd-parity architecture: OK (5 one-bits) OK (5 one-bits) error (4 one-bits) error (4 one-bits)
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)
Questions? Do Homework #1 Quiz #1 Wednesday