- 59 Views
- Uploaded on
- Presentation posted in: General

Announcements

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

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 topics

- More internal representation
- Signed/unsigned integers

- External representation
- Binary, decimal, hexadecimal number systems

- Binary arithmetic
- Floating-point representation
- Error-detecting and error-correcting codes

Other representations

- Every integer number has a unique representation in each "base" 2
- Hexadecimal is commonly used for easily converting binary to a more manageable form.
- example 16-bit binary hexadecimal:
Binary 0001 0111 1011 1101

Hexadecimal 1 7 B D

Write it as 0x17BD or 17BDh

Converting decimal to hexadecimal

- Use same methods as decimal to binary
- The only difference is the place values

- Example decimal to hexadecimal
157 decimal = 9D hex(0x9D or 9Dh)

- … 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?
- Recall that a 16-bit signed integer is negative if the leftmost bit is 1

- 16-bit (4 hex digits) examples:
- 0x7a3e is positive
- 0x8a3e is negative
- 0xFFFF is negative

Character and control codes

- Letters, digits, special characters … are represented internally as numbers
- ASCII256 codes (1-byte)
- e.g., 'A' … 'Z' are codes 65 - 90
- e.g., '0' … '9' are codes 48 - 57

- Unicode65,536 codes (2-byte)
- Some codes are used for controlling devices
- e.g., code 10 is “new line” for output device
- e.g., code 27 is “escape”

- Device controllers translate codes (device-dependent)
- All keyboard input is character (including digits)

Digits

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

- What happens if we add ‘3’ + ‘5’?
- The answer is ‘h’

- Numeric data types require conversion by the input/output operations

Neutral representation

- Inside the computer
- Bytes, words, etc., can represent some finite number of combinations of off/on switches.
- Each distinct combination is called a code.
- Each code can be used to represent:
- numeric value
- memory address
- machine instruction
- keyboard character

- 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
- Everything extends to 16-bit, 32-bit, n-bit representations.
- 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.

Addition

- Specify result size (bits)
- Use the usual rules of add and carry
- 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

- Example:
00101101

+00011110

01001011

- How does overflow occur?

Subtraction

- Use the usual rules
- Order matters
- Borrow and subtract

- Example:
- … or negate and add
- Example:

- How does underflow occur?

Verification

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

Multiplication

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

Division

- Usual algorithm
- Repeated subtraction
- … or shift right (if divisor is a power of 2)
- too complicated if divisor is not a power of 2

- Check underflow for remainder

Arithmetic operations

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

Floating-point representation

- “decimal” means “base ten”
- “floating-point” means “a number with an integral part and a fractional part
- Sometimes call “real”, “float”

- Generic term for “decimal point” is “radix point”

Converting floating-point (decimal binary)

- Place values:

Integral part

Fractional part

Example: 4.5 (decimal) = 100.1 (binary)

Converting floating-point (decimal binary)

- Example:6.25 = 110.01
- 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

- 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

Internal representation of floating-point numbers

- Some architectures handle the integer part and the fraction part separately
- Slow

- Most use a completely different representation and a different ALU (IEEE standard)
- Range of values for 32-bit
- Approximately -3.4 x 1038 … +3.4 x 1038

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

IEEE 754 standard

- single-precision (32-bit)
- double-precision (64-bit)
- extended (80-bit)
- 3 parts
- 1 sign bit
- "biased" exponent (single: 8 bits,
double: 11 bits

extended: 15 bits)

- "normalized" mantissa (single: 23 bits,
double: 52 bits

extended: 64 bits)

Examples:

Sign

Biased exponent

Normalized mantissa

- 6.25 in IEEE single precision is
0 10000001 10010000000000000000000

0100 0000 1100 1000 0000 0000 0000 0000

40C80000 hexadecimal

- 6.2 in IEEE is
0 10000001 10001100110011001100110

0100 0000 1100 0110 0110 0110 0110 0110

40C66666 hexadecimal

Examples:

- 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.1001x 22

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

01000000110010000000000000000000

0100 0000 1100 1000 0000 0000 0000 0000

40C80000 hexadecimal

Examples:

- 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 22

… so the sign bit is 0 (positive)

… the “biased” exponent is 2 + 127 = 129= 10000001

… and the “normalized” mantissa is 10001100110011…

(drop the 1).

01000000110001100110011001100110

0100 0000 1100 0110 0110 0110 0110 0110

40C66666 hexadecimal

Example:

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

11000001100001110000000000000000

… so the sign is negative

… the “unbiased” exponent is 131 - 127 = 4

… 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

- -10000.111 = -16.875

Sign

Biased exponent

Normalized mantissa

Internal representation

- Regardless of external representation, all I/O eventually is converted into electrical (binary) codes.
- 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.
- 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 ?
- 0

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

- 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 ?
- Representations may be truncated; overflow / underflow can occur, and the Status Register will be set
- Limited precision for floating-point representations

Looking inside …

- 11010110What does this code represent?
- Number ?
- 8-bit unsigned 214 ?
- 8-bit signed - 42 ?
- partial 16-bit integer ?
- partial floating point ?

- Character ?
- ASCII ‘╓’ ?
- partial Unicode ‘Ö’

- Address ?
- Instruction ?
- Garbage ?

Neutral representation

- Inside the computer
- Bytes, words, etc., can represent a finite number of combinations of off/on switches.
- Each distinct combination is called a code.
- Each code can be used to represent:
- numeric value
- memory address
- machine instruction
- keyboard character

- 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
- 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 (error checking)

- 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)
- Odd-parity system:011010110(sets parity bit to 0 to keep 5 one-bits)

- Code is checked for parity error whenever it is used.
- Examples for even-parity architecture:
- 101010101error (5 one-bits)
- 100101010OK (4 one-bits)

- Examples for odd-parity architecture:
- 101010101OK (5 one-bits)
- 100101010error (4 one-bits)

Parity (error checking)

- Used for checking memory, network transmissions, etc.
- Error detection

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

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

Questions?

Do Homework #1

Quiz #1 Thursday 7/1