Title: Class
1Class 3 Addressing Data Representation
- Addressing
- A. Modes
- B. Examples
- II. Binary Number Operations
- A. Numbers with radix point
- B. Floating Point Notation (IEEE 754 Standard)
- C. Floating Point Arithmetic Operations
- D. Multiplication Division
- III. Representing Pictures and Audio
- A. Digitizing Images -gt Binary
- B. Digitizing Audio - gt Binary
- IV. Data Structures
- A. Stacks
- B. Reverse Polish Notation (RPN)
- C. Big Endian Little Endian
2Addressing Modes
- Immediate
- Direct
- Indirect
- Register
- Register Indirect
- Displacement (Indexed)
3Immediate Addressing
- Operand is part of instruction
- e.g. ADD 5
- Add 5 to contents of accumulator
- 5 is operand
- No memory reference to fetch data
- Fast
- Limited range
Instruction
Operand
Opcode
4Direct Addressing
- Common in early generations of computers
- Address field contains address of operand
- Effective address (EA) address field (A)
- e.g. ADD A
- Add contents of cell A to accumulator
- Look in memory at address A for operand
- Single memory reference to access data
- No additional calculations to work out effective
address - Limited address space
5Direct Addressing Diagram
Instruction
Address A
Opcode
Memory
Operand
6Indirect Addressing
- Memory cell pointed to by address field contains
the address of (pointer to) the operand - EA (A)
- Look in A, find address (A) and look there for
operand - e.g. ADD (A)
- Add contents of cell pointed to by contents of A
to accumulator - Large address space 2n where n word length
- Multiple memory accesses to find operand
- Hence slower
7Indirect Addressing Diagram
Instruction
Address A
Opcode
Memory
Pointer to operand
Operand
8Register Addressing
- Operand is held in register named in address
field - EA R
- Limited number of registers
- Very small address field needed
- Shorter instructions
- Faster instruction fetch
- No memory access very fast execution
- Very limited address space
- Multiple registers helps performance
- Requires good assembly programming or compiler
writing - N.B. C programming
- register int a
- c.f. Direct addressing
9Register Addressing Diagram
Instruction
Register Address R
Opcode
Registers
Operand
10Register Indirect Addressing
- C.f. indirect addressing
- EA (R)
- Operand is in memory cell pointed to by contents
of register R - Large address space (2n)
- One fewer memory access than indirect addressing
11Register Indirect Addressing Diagram
Instruction
Register Address R
Opcode
Memory
Registers
Operand
Pointer to Operand
12Displacement Addressing
- EA A (R)
- Address fields hold two values
- A base value
- R register that holds displacement
- or vice versa
- Flavors
- PC Relative addressing
- Base-register addressing
- Indexing
13Displacement Addressing Diagram
Instruction
Address A
Register R
Opcode
Memory
Registers
Pointer to Operand
Operand
14PC-Relative Addressing
- A version of displacement addressing
- R Program counter, PC
- EA A (PC)
- i.e. get operand from A cells from current
location pointed to by PC - Often used with branch instruction
15Base-Register Addressing
- A holds displacement
- R holds pointer to base address
- R may be explicit or implicit
- e.g. segment registers in 80x86
16Indexed Addressing
- A base
- R displacement
- EA A R
- Good for accessing arrays
- EA A R
- R (increment next element in array)
17Pentium Addressing Modes
- Virtual or effective address is offset into
segment - Starting address plus offset gives linear address
- This goes through page translation if paging
enabled - 12 addressing modes available
- Immediate
- Register operand
- Displacement
- Base
- Base with displacement
- Scaled index with displacement
- Base with index and displacement
- Base scaled index with displacement
- Relative
18Addressing Example
- Q If mode indicates a source register it is R1
which has a value of 200. There is also a base
register that contains the value 100. Location
499 contains the value 999, location 500 contains
the value 1000 and so on. What is the effective
address and operand for the following?
Answer
19Binary Real Numbers
- A real number can contain both whole and
fractional components - 18.0 divided by 4.0 4.5
- 10010 / 100 100.1 (can be done by long
division) - We can represent non-integer numbers in binary by
use of a radix point. - Q 1 What is 96.375
- in binary?
- Q 2 What is 11001.1101
- in decimal?
20Adding Numbers with Radix Points
- What is 101101.101 10100.1010?
- You have align the radix points in order to get
the answer - 101101.101 45.625
- 10100.1011 20.6875
- 1000010.0101 66.3125
- (ones carry from right of radix point to left
of it)
21Floating Point Notation
- Floating point notation is used to represent very
small numbers and very large numbers - The exponent attached to the base can be
interpreted as the number and the direction of
positional moves of the radix point - Negative exponents indicate a movement to the
left, and positive exponents indicate movement to
the right
22Floating Point Numbers
- Components
- Sign bit
- Exponent
- Assumed radix point
- Assumed (hidden) 1
- Mantissa
23The Sign Mantissa
- The Sign
- A 1 bit indicates a negative number, and a 0 bit
indicates a positive number. - The Mantissa
- Decimal 0.154 1/10 5/100 4/1000
- Binary 0.1011 1/2 0/4 1/8 1/16
- For the above binary number, we have a
normalized binary number of 1.011 x 2-1 - The sign is positive (0), the exponent is -1 and
the mantissa for an IEEE 754 floating point
number is 011. - Why is the mantissa NOT 1011?
24The Exponent
- IEEE 754 Short (32-bit) real exponents are
stored as 8-bit unsigned integers with a bias of
127.
Actual Exponent Adjusted Exponent - 127
25Normalized Mantissa
- What are the following floating point numbers in
binary decimal? - 10111111 00000000 00000000 00000000
- Negative, exp126-127 -1, mantissa 0, 1.0 x
2-1 - (0.10)2 -(1/2)10 - 00111111 10000000 00000000 00000000
- Positive, exp127-127 0, mantissa 0, 1.0 x
20 (1)2 (1)10 - 3F880000H 00111111 10001000 00000000 00000000
- Positive, exp0, mantissa 0001, 1.0001 x 20
(1.0001)2 (1.0625)10
26Single Precision Double Precision
- All 1s in exponent infinity
- All 0s in exponent zero
27Problems with Floating Point s
- Overflow occurs when the exponent is larger than
the allocated space. - Underflow occurs when a negative exponent is too
large in absolute value to fit within the bits
allocated to store it. - Truncation occurs when the there are not enough
digits in the mantissa to represent the number. - Examples
- 1/3 in decimal 0.3333333...
- 1/10 cannot be represented accurately as a
floating point number (many others also). Problem
with !
28Floating Point Arithmetic
- Floating point addition / subtraction
- Floating point multiplication/ division
- Floating point arithmetic differs from integer
- arithmetic because exponents and fraction must
be - handled separately differently.
29Floating Point Addition/Subtraction
- The exponents of the operands must be made equal
for addition and subtraction. The fractions are
then added or subtracted as appropriate. The
result is normalized. - Example (.10123 .111 24)2
- Start by adjusting the smaller exponent to be
equal to the larger exponent, and modify the
fraction accordingly. Thus we have .101 23
.0101 24. - The resulting sum is (.0101 .1110) 24
1.001124 .1001125 - 5 14 19
- Note, the hidden bit 1 is made explicit
during calculations.
30Floating Point Addition/Subtraction
- Procedures
- Check for zeros
- Adjust exponents and align significands
- Add or subtract significands
- Normalize result
31Floating Point Addition/Subtraction Flowchart
32Unsigned Multiplication
- Multiplication involves the generation of partial
products. - Each successive partial product is shifted one
position to the left relative to the preceding
partial product. - The total result is produced by summing the
partial products. - Multiplication of two n-bit unsigned binary
integers produces a 2n-bit result.
33Flowchart for Unsigned Binary Multiplication
34Unsigned Division
- Example 147/11 13 remainder 4
- Examine the dividend from left to right, until
the set of bits is greater than or equal to the
divisor. - Place 1 in the quotient and subtract the
divisor from the partial dividend. The result is
partial remainder. - Additional bits from the dividend are appended
to the partial remainder until the partial
remainder is greater than or equal to the
divisor. - Repeat step 2, until all the bits of the
dividend are exhausted.
35Flowchart for Unsigned Binary Division
36Multiplication Division of Signed Integers
- The general technique for multiplication and
division of signed integers is to convert the
operands into their positive forms, perform the
division, and then convert the result into its
true signed form as a final step. - Booths algorithm is a way to multiply signed
numbers. -
37Floating Point Multiplication/Division
- For floating point multiplication/division, the
sign, exponent and fraction of the - result are computed separately.
- Sign Like/unlike signs produce
positive/negative results. - Exponent Adding exponents for
multiplication. - Subtracting exponents for
division. - Fractions Multiplying or dividing as for
fix point numbers. - Normalizing the final result.
- Example (.110 25) / (.100 24)2
- The source operand signs are the same, so the
result has a positive sign. - Subtracting exponents for division 5 4 1.
- Dividing fractions 110/100 1.10.
- Putting it all together (.110 25) / (.100
24) (1.10 21).
38Representing Images
Each pixel color is represented by a certain
binary string. The number of pixels determines
the resolution.
39Color Bit Depth per Pixel
- RGB One byte for each primary color
40Example
- Q1 For a bit-map terminal with 1024 x 768 pixel
display and 24-bit color, what is the data rate
for an uncompressed video at 30 frames/sec? - A 1024x768 786,432 pixels, with 24-bits/pixel
we have 786,432 x 24 18,874,368 bits/frame - With 30 frame/sec x 18,874,368 bits/frame
- 566,231,040 bits/sec approx. 566Mbps
-
41Representing Audio Signals
- You have done this already!
- Remember Pulse Code Modulation (PCM)?
- Sampling (Nyquist rate)
- Quantization (what does this affect?)
- Encoding (what can we do here to improve
reliability?)
42Stacks
- Contiguous block of reserved space in main memory
- A data structure for variable numbers of items.
Used because of not enough registers in CPU- so
main memory is used instead. - Stack is a LIFO (last in, first out) queue.
- - Stack expands as data is added
- - Stack contracts as data is removed
43Stack Operation
44Stack Organization
- Stack Limit End of block in main memory (usually
lowest address in reserved space) - Stack Pointer Address of top of stack
- Stack Base Address of bottom of stack (usually
highest address in reserved space) - Usually top two stack elements in registers (WHY?)
45Stack Expression Evaluation
46Reverse Polish Notation (postfix)
- Polish Notation was invented in the 1920's by
Polish mathematician Jan Lukasiewicz, who showed
that by writing operators in front of their
operands, instead of between them, brackets were
made unnecessary. - Reverse Polish Notation puts the operators at the
end (Dijkstra). It is used in stack operations. - a b becomes ab
- a (b x c) becomes abcx
- (a b) x c becomes abcx
47Byte Order
- What order do we read numbers that occupy more
than one byte? - e.g. (numbers in hex to make it easy to read)
- 12345678 can be stored in 4x8bit locations as
follows - Do we read top down or bottom up??
48Byte Order Names
- The problem is called Endian
- The system on the left has the most significant
byte in the lowest address for number 12345678 - This is called big-endian
- The system on the right has the least
significant byte in the lowest address for number
12345678 - This is called little-endian
Little used by Intel, VAX, Alpha
Big used by IBM, Motorola, Sun, RISC
49Example of C Data Structure
50Alternative View of Memory Map
51Endian Example
- Big endian versus little endian
Name JIM SMITH Age 21 Dept 260
52StandardWhat Standard?
- Pentium (80x86), VAX are little-endian
- IBM 370, Motorola 680x0 (Mac), and most RISC are
big-endian - Internet is big-endian
- Makes writing Internet programs on PC more
awkward! - WinSock provides htoi and itoh (Host to Internet
Internet to Host) functions to convert