announcements quiz #1 in class thursday, july 1st covers virtual machine (levels) computer languages...

34
Announcements Quiz #1 In class Thursday, July 1st 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 Permitted: Calculator and one 8x11 notesheet (one sides) No sharing

Upload: derek-fox

Post on 23-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Announcements

Quiz #1 In class Thursday, July 1st 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 Permitted: Calculator and one 8x11 notesheet (one

sides) No sharing

Today’s topicsToday’s topics More internal representationMore internal representation

Signed/unsigned integersSigned/unsigned integers External representationExternal representation

Binary, decimal, hexadecimal number Binary, decimal, hexadecimal number systemssystems

Binary arithmeticBinary arithmetic Floating-point representationFloating-point representation Error-detecting and error-correcting Error-detecting and error-correcting

codescodes

Other representationsOther representations Every integer number has a unique Every integer number has a unique

representation in each "base" representation in each "base" 2 2 HexadecimalHexadecimal is commonly used for is commonly used for

easily converting binary to a more easily converting binary to a more manageable form.manageable form.

example 16-bit binary example 16-bit binary hexadecimal:hexadecimal:BinaryBinary 0001 0111 1011 1101 0001 0111 1011 1101

Hexadecimal 1 7 B DHexadecimal 1 7 B D

Write it as 0x17BD or 17BDhWrite it as 0x17BD or 17BDh

Converting decimal to Converting decimal to hexadecimalhexadecimal

Use same methods as decimal to Use same methods as decimal to binarybinary The only difference is the place valuesThe only difference is the place values

Example decimal to hexadecimalExample decimal to hexadecimal

157 decimal = 9D hex157 decimal = 9D hex (0x9D or 9Dh)(0x9D or 9Dh) … … or convert to binary, then to hexor convert to binary, then to hex

Negative hex (signed Negative hex (signed integers)integers)

How can you tell if a hexadecimal How can you tell if a hexadecimal representation of a signed integer is representation of a signed integer is negative?negative? Recall that a 16-bit signed integer is Recall that a 16-bit signed integer is

negative if the leftmost bit is 1negative if the leftmost bit is 1 16-bit (4 hex digits) examples:16-bit (4 hex digits) examples:

0x7a3e is positive0x7a3e is positive 0x8a3e is negative0x8a3e is negative 0xFFFF is negative0xFFFF is negative

Character and control codesCharacter and control codes Letters, digits, special characters … are Letters, digits, special characters … are

represented internally as numbersrepresented internally as numbers ASCIIASCII 256 codes (1-byte)256 codes (1-byte)

e.g., 'A' … 'Z' are codes 65 - 90e.g., 'A' … 'Z' are codes 65 - 90 e.g., '0' … '9' are codes 48 - 57e.g., '0' … '9' are codes 48 - 57

UnicodeUnicode 65,536 codes (2-byte)65,536 codes (2-byte) Some codes are used for controlling Some codes are used for controlling

devicesdevices e.g., code 10 is “new line” for output devicee.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-Device controllers translate codes (device-dependent)dependent)

All keyboard input is All keyboard input is charactercharacter (including (including digits)digits)

DigitsDigits

Digits entered from the keyboard are Digits entered from the keyboard are characterscharacters E.G., ‘0’ is character number 48, … ‘9’ is E.G., ‘0’ is character number 48, … ‘9’ is

character number 57character 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 Numeric data types require conversion by the input/output conversion by the input/output operationsoperations

Neutral representationNeutral representation

Inside the computerInside the computer Bytes, words, etc., can represent some finite Bytes, words, etc., can represent some finite

number of combinations of off/on switches.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 valuenumeric value memory addressmemory address machine instructionmachine instruction keyboard characterkeyboard character

Representation is neutral. Representation is neutral. The operating The operating system and the programs decide how to system and the programs decide how to interpret the codes.interpret the codes.

Arithmetic operationsArithmetic operations The following examples use 8-bit The following examples use 8-bit

twos-complement twos-complement operandsoperands Everything extends to 16-bit, 32-bit, Everything extends to 16-bit, 32-bit,

n-bit representations. n-bit representations. What is the What is the range of valuesrange of values for 8-bit for 8-bit

operands?operands? The usual arithmetic operations The usual arithmetic operations

can be performed directly in can be performed directly in binary form with n-bit binary form with n-bit representations.representations.

AdditionAddition

Specify result size (bits)Specify result size (bits) Use the usual rules of add and carryUse the usual rules of add and carry

With two operands, the With two operands, the carry bitcarry bit is never is never greater than onegreater than one

0+0+0+0+11 = 1, = 1, 0+1+0+1+11 = 10, = 10, 1+0+1+0+11 = 10, = 10,1+1+1+1+11 = 11 = 11

Example:Example:0010110100101101

++00011110000111100100101101001011

How does How does overflowoverflow occur? occur?

SubtractionSubtraction Use the usual rulesUse the usual rules

Order mattersOrder matters Borrow and subtractBorrow and subtract

Example:Example:

… … or negate and addor negate and add Example:Example:

How does How does underflowunderflow occur? occur?

VerificationVerification

Perform operation on binary Perform operation on binary operandsoperands

Convert result to decimalConvert result to decimal Convert operands to decimalConvert operands to decimal Perform operation on decimal Perform operation on decimal

operandsoperands [Convert result to binary][Convert result to binary] Compare resultsCompare results

MultiplicationMultiplication

Usual algorithmUsual algorithm

Repeated additionRepeated addition

… … or shift left (and adjust if multiplier is or shift left (and adjust if multiplier is not a power of 2)not a power of 2)

Check for overflowCheck for overflow

DivisionDivision

Usual algorithmUsual algorithm

Repeated subtractionRepeated 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 2too complicated if divisor is not a power of 2

Check underflow for remainderCheck underflow for remainder

Arithmetic operationsArithmetic operations

Note: Note: allall of the arithmetic operations of the arithmetic operations can be accomplished using can be accomplished using onlyonly addadd complementcomplement

Floating-point Floating-point representationrepresentation

““decimal” means “base ten”decimal” means “base ten” ““floating-point” means “a number floating-point” means “a number

with an integral part and a fractional with an integral part and a fractional partpart Sometimes call “real”, “float”Sometimes call “real”, “float”

Generic term for “decimal point” is Generic term for “decimal point” is ““radixradix point point””

Converting floating-point Converting floating-point (decimal (decimal binary) binary)

Place values:Place values:

2255 2244 2233 2222 2211 2200 22-1-1 22-2-2 22-3-3 22-4-4 22-5-5

3232 1616 88 44 22 11 0.50.5 0.250.25 0.1250.125 0.06250.0625 0.031250.03125

Integral part Fractional part

Example: 4.5 (decimal) = 100.1 (binary)

Converting floating-point Converting floating-point (decimal (decimal binary) binary)

Example:Example: 6.25 = 110.016.25 = 110.01 Method:Method:

6 = 6 = 110110 (Integral part: convert in the usual way)(Integral part: convert in the usual way).25 x 2 = .25 x 2 = 00.5.5 (Fractional part: successive multiplication (Fractional part: successive multiplication

by 2)by 2).5 x 2 = .5 x 2 = 11.0.0 (Stop when fractional part is 0)(Stop when fractional part is 0) 110.01110.01

Example:Example: 6.2 6.2 110.001100110011… 110.001100110011…6 = 6 = 110110.2 x 2 = .2 x 2 = 00.4.4.4 x 2 = .4 x 2 = 00.8.8.8 x 2 = .8 x 2 = 11.6.6.6 x 2 = .6 x 2 = 11.2.2.2 x 2 = 0.4.2 x 2 = 0.4 (repeats)(repeats) 110.0011 0011 0011110.0011 0011 0011

Internal representation of Internal representation of floating-point numbersfloating-point numbers

Some architectures handle the integer Some architectures handle the integer part and the fraction part separatelypart and the fraction part separately SlowSlow

Most use a completely different Most use a completely different representation and a different ALU (IEEE representation and a different ALU (IEEE standard)standard)

Range of values for 32-bitRange of values for 32-bit Approximately -3.4 x 10Approximately -3.4 x 103838 … +3.4 x 10 … +3.4 x 103838

Limited precisionLimited precision Approximately -1.4 x 10Approximately -1.4 x 10-45-45 … +1.4 x 10 … +1.4 x 10-45-45

IEEE 754 standardIEEE 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 parts3 parts

1 1 signsign bit bit "biased" "biased" exponentexponent (single: 8 bits, (single: 8 bits,

double: 11 bitsdouble: 11 bits extended: 15 bits)extended: 15 bits)

"normalized" "normalized" mantissamantissa (single: 23 bits, (single: 23 bits, double: 52 bitsdouble: 52 bits extended: 64 bits)extended: 64 bits)

Examples:Examples:

6.25 in IEEE single precision is6.25 in IEEE single precision is0 10000001 100100000000000000000000 10000001 10010000000000000000000

0100 0000 1100 1000 0000 0000 0000 00000100 0000 1100 1000 0000 0000 0000 0000

40C80000 hexadecimal40C80000 hexadecimal 6.2 in IEEE is6.2 in IEEE is

0 10000001 100011001100110011001100 10000001 10001100110011001100110

0100 0000 1100 0110 0110 0110 0110 01100100 0000 1100 0110 0110 0110 0110 0110

40C66666 hexadecimal40C66666 hexadecimal

Sign Biased exponent Normalized mantissa

Examples:Examples: 6.25 in IEEE single precision6.25 in IEEE single precision

6.25 (decimal) = 6.25 (decimal) = 110.01110.01 (binary) (binary)Move the radix point until a single 1 appears on Move the radix point until a single 1 appears on

the the leftleft, and multiply by the corresponding , and multiply by the corresponding power of 2power of 2

= = 11..10011001 xx 2 222

… 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).

00 1000000110000001 1001000000000000000000010010000000000000000000

0100 0000 1100 1000 0000 0000 0000 0100 0000 1100 1000 0000 0000 0000 00000000

40C80000 hexadecimal40C80000 hexadecimal

Examples:Examples: 6.2 in IEEE is6.2 in IEEE is

6.2 (decimal) = 110.001100110011… (binary)6.2 (decimal) = 110.001100110011… (binary)

Move the radix point until a single 1 appears on the Move the radix point until a single 1 appears on the leftleft, and multiply by the corresponding power of , and multiply by the corresponding power of 22

= = 11..10001100110011…10001100110011… xx 2 222

… so the sign bit is 0 (positive)… the “biased” exponent is 2 + 127 = 129= 10000001

… and the “normalized” mantissa is 10001100110011…10001100110011…(drop the 1).

00 1000000110000001 1000110011001100110011010001100110011001100110

0100 0000 1100 0110 0110 0110 0110 01100100 0000 1100 0110 0110 0110 0110 0110

40C66666 hexadecimal40C66666 hexadecimal

What decimal floating-point number is What decimal floating-point number is represented by C1870000H?represented by C1870000H?1100 0001 1000 0111 0000 0000 0000 00001100 0001 1000 0111 0000 0000 0000 000011 1000001110000011 0000111000000000000000000001110000000000000000

… so the sign is negative… the “unbiased” exponent is 131 - 127 = 4… and the “unnormalized” mantissa is

1.0000111000000000000000000001110000000000000000 (add the 1 left of the radix point).

Move the radix point 4 places to the right: 10000.111

-10000.111 = -16.875 = -16.875

Example:Example:

Sign Biased exponent

Normalized mantissa

Internal representationInternal representation

Regardless of external Regardless of external representation, all I/O eventually is representation, all I/O eventually is converted into electrical (binary) converted into electrical (binary) codes.codes.

Inside the computer, everything is Inside the computer, everything is represented by gates (open/closed).represented by gates (open/closed).

Problem with Internal Problem with Internal RepresentationRepresentation

Since the number of gates in each group (byte, Since the number of gates in each group (byte, word, etc.) is finite, computers can represent word, etc.) is finite, computers can represent numbers with numbers with finite precisionfinite precision only. only.

Examples:Examples: Suppose that signed integer data is represented using Suppose that signed integer data is represented using

16 bits. The largest integer that can be represented is 16 bits. The largest integer that can be represented is 65535. What happens if we add 1 ? 65535. What happens if we add 1 ?

00 What happens when we need to represent 1/3 ?What happens when we need to represent 1/3 ?

Representations may be Representations may be truncatedtruncated; ; overflowoverflow / / underflowunderflow can occur, and the Status Register will can occur, and the Status Register will be setbe set

Limited precisionLimited precision for floating-point for floating-point representationsrepresentations

Looking inside …Looking inside … 1101011011010110What 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 representationNeutral representation

Inside the computerInside the computer Bytes, words, etc., can represent a finite Bytes, words, etc., can represent a finite

number of combinations of off/on switches.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 valuenumeric value memory addressmemory address machine instructionmachine instruction keyboard characterkeyboard character

Representation is neutral. Representation is neutral. The operating The operating system and the programs decide how to system and the programs decide how to interpret the codes.interpret the codes.

Simple Error CheckingSimple Error Checking

Each computer architecture is Each computer architecture is designed to use either designed to use either even parityeven parity or or odd parityodd parity

System adds a System adds a parity bitparity bit to make to make each code match the system's parityeach code match the system's parity

ParityParity is the total number of '1' bits is the total number of '1' bits (including the extra parity bit) in a (including the extra parity bit) in a binary codebinary code

Parity (error checking)Parity (error checking) Example parity bits for 8-bit code Example parity bits for 8-bit code

1101011011010110 Even-parity systemEven-parity system::111101011011010110 (sets parity bit (sets parity bit

to to 11 to make a total of 6 one-bits) to make a total of 6 one-bits) Odd-parity systemOdd-parity system:: 001101011011010110 (sets parity bit (sets parity bit

to to 00 to keep 5 one-bits) to keep 5 one-bits)

Code is checked for Code is checked for parity errorparity error whenever whenever it is used.it is used.

Examples for even-parity architecture:Examples for even-parity architecture: 101010101101010101 errorerror (5 one-bits) (5 one-bits) 100101010100101010 OK (4 one-bits)OK (4 one-bits)

Examples for odd-parity architecture:Examples for odd-parity architecture: 101010101101010101 OK (5 one-bits)OK (5 one-bits) 100101010100101010 errorerror (4 one-bits) (4 one-bits)

Parity (error checking)Parity (error checking)

Used for checking memory, network Used for checking memory, network transmissions, etc.transmissions, etc. Error Error detectiondetection

Not 100% reliable.Not 100% reliable. Works only when error is in odd number of bitsWorks only when error is in odd number of bits … … but very good because most errors are but very good because most errors are

single-bitsingle-bit

Next time …Next time … Error-Error-correctingcorrecting codes (ECC) codes (ECC)

Questions?Questions?

Do Homework #1Do Homework #1Quiz #1 Thursday 7/1Quiz #1 Thursday 7/1