Problem 1
(a) Multiply the following signed 2's complement 8-bit numbers using Booth's Algorithm. Show all the steps as in Figure 4.35 on page 262 of
the course text.
Verify your answer by converting A and B and your result (A * B) to decimal.
A = 1001 1011 B = 0010 1001
iter |
Step |
Multiplicand |
product |
0 |
Initial value |
0010 1001 |
0000 0000 1001 1011 0 |
1 |
10 => P = P - Mcand |
0010 1001 |
1101 0111 1001 1011 0 |
Shift right product |
0010 1001 |
1110 1011 1100 1101 1 |
|
2 |
11 => No op |
0010 1001 |
1110 1011 1100 1101 1 |
Shift right product |
0010 1001 |
1111 0101 1110 0110 1 |
|
3 |
01 => Prod = Prod + Mcand |
0010 1001 |
0001 1110 1110 0110 1 |
Shift right product |
0010 1001 |
0000 1111 0111 0011 0 |
|
4 |
10 => Prod = Prod - Mcand |
0010 1001 |
1110 0110 0111 0011 0 |
Shift right product |
0010 1001 |
1111 0011 0011 1001 1 |
|
5 |
11 => No op |
0010 1001 |
1111 0011 0011 1001 1 |
Shift right product |
0010 1001 |
1111 1001 1001 1100 1 |
|
6 |
01 => Prod = Prod + Mcand |
0010 1001 |
0010 0010 1001 1100 1 |
Shift right product |
0010 1001 |
0001 0001 0100 1110 0 |
|
7 |
00 => No op |
0010 1001 |
0001 0001 0100 1110 0 |
Shift right product |
0010 1001 |
0000 1000 1010 0111 0 |
|
8 |
10 => Prod = Prod - Mcand |
0010 1001 |
1101 1111 1010 0111 0 |
Shift right product |
0010 1001 |
1110 1111 1101 0011 1 |
Final result is 1110 1111 1101 0011b = -4141
Multiplicand 0010 1001b = 41, Multiplier 1001 1011 = -101; 41 * -101 = -4141
(b) Repeat (a) using the modified Booth's algorithm.
iter |
Step |
Multiplicand |
product |
0 |
Initial value |
0010 1001 |
0000 0000 1001 1011 0 |
1 |
110 => P = P - Mcand |
0010 1001 |
1101 0111 1001 1011 0 |
Shift right 2 bits product |
0010 1001 |
1111 0101 1110 0110 1 |
|
2 |
101 => P = P - Mcand |
0010 1001 |
1100 1100 1110 0110 1 |
Shift right 2 bits product |
0010 1001 |
1111 0011 0011 1001 1 |
|
3 |
011 => P = P + 2 * Mcand |
0010 1001 |
0100 0101 0011 1001 1 |
Shift right 2 bits product |
0010 1001 |
0001 0001 0100 1110 0 |
|
4 |
100 => P = P - 2 * Mcand |
0010 1001 |
1011 1111 0100 1110 0 |
Shift right 2 bits product |
0010 1001 |
1110 1111 1101 0011 1 |
Final result is 1110 1111 1101 0011 = -4141, same as above.
Problem 2
(a) Divide the following positive numbers using the restoring division
algorithm. Show all the steps as in Figure 4.38 on page 268 of the
course text.
Verify your answer by converting A and B and your result (A / B) to decimal.
A = 1011 0101 B = 1010
iter |
Step |
Divisor |
Part. Remainder / Dividend |
0 |
Initial value |
1010 |
0000 0000 1011 0101 |
1 |
Shift << 1 |
1010 |
0000 0001 0110 1010 |
Rem = Rem - Div |
1010 |
1111 0111 0110 1010 |
|
Rem < 0 -> restore |
1010 |
0000 0001 0110 1010 |
|
2 |
Shift << 1 |
1010 |
0000 0010 1101 0100 |
Rem = Rem - Div |
1010 |
1111 1000 1101 0100 |
|
Rem < 0 -> restore |
1010 |
0000 0010 1101 0100 |
|
3 |
Shift << 1 |
1010 |
0000 0101 1010 1000 |
Rem = Rem - Div |
1010 |
1111 1011 1010 1000 |
|
Rem < 0 -> restore |
1010 |
0000 0101 1010 1000 |
|
4 |
Shift << 1 |
1010 |
0000 1011 0101 0000 |
Rem = Rem - Div |
1010 |
0000 0001 0101 0000 |
|
Rem > 0 -> put 1 in LSB of Rem |
1010 |
0000 0001 0101 0001 |
|
5 |
Shift << 1 |
1010 |
0000 0010 1010 0010 |
Rem = Rem - Div |
1010 |
1111 1000 1010 0010 |
|
Rem < 0 -> restore |
1010 |
0000 0010 1010 0010 |
|
6 |
Shift << 1 |
1010 |
0000 0101 0100 0100 |
Rem = Rem - Div |
1010 |
1111 1011 0100 0100 |
|
Rem < 0 -> restore |
1010 |
0000 0101 0100 0100 |
|
7 |
Shift << 1 |
1010 |
0000 1010 1000 1000 |
Rem = Rem - Div |
1010 |
0000 0000 1000 1000 |
|
Rem > 0 -> put 1 in LSB of Rem |
1010 |
0000 0000 1000 1001 |
|
8 |
Shift << 1 |
1010 |
0000 0001 0001 0010 |
Rem = Rem - Div |
1010 |
1111 0111 0001 0010 |
|
Rem < 0 -> restore |
1010 |
0000 0001 0001 0010 |
Final result is quotient 0001 0010b = 18 remainder 0000_0001b = 1
A = 1011 0101 = 181; B = 1010 = 10; 181/10 = 18, remainder 1
(b) Repeat using the non-restoring algorithm. Be sure to show all steps.
iter |
Step |
Divisor |
Part. Remainder / Dividend |
0 |
Initial value |
1010 |
0000 0000 1011 0101 |
1 |
Shift << 1 |
1010 |
0000 0001 0100 1010 |
PR = PR - D |
1010 |
1111 0111 0110 1010 |
|
Rem < 0, do nothing |
1010 |
1111 0111 0110 1010 |
|
2 |
Shift << 1 |
1010 |
1110 1110 1101 0100 |
Rem < 0, Rem = Rem + Div |
1010 |
1111 1000 1101 0100 |
|
Rem < 0, do nothing |
1010 |
1111 1000 1101 0100 |
|
3 |
Shift << 1 |
1010 |
1111 0001 1010 1000 |
Rem < 0, Rem = Rem + Div |
1010 |
1111 1011 1010 1000 |
|
Rem < 0, do nothing |
1010 |
1111 1011 1010 1000 |
|
4 |
Shift << 1 |
1010 |
1111 0111 0101 0000 |
Rem < 0, Rem = Rem + Div |
1010 |
0000 0001 0101 0000 |
|
Rem > 0, set LSB 1 |
1010 |
0000 0001 0101 0001 |
|
5 |
Shift << 1 |
1010 |
0000 0010 1010 0010 |
Rem > 0, Rem = Rem - Div |
1010 |
1111 1000 1010 0010 |
|
Rem < 0, do nothing |
1010 |
1111 1000 1010 0010 |
|
6 |
Shift << 1 |
1010 |
1111 0001 0100 0100 |
Rem < 0, Rem = Rem + Div |
1010 |
1111 1011 0100 0100 |
|
Rem < 0, do nothing |
1010 |
1111 1011 0100 0100 |
|
7 |
Shift << 1 |
1010 |
1111 0110 1000 1000 |
Rem < 0, Rem = Rem + Div |
1010 |
0000 0000 1000 1000 |
|
Rem > 0, set LSB 1 |
1010 |
0000 0000 1000 1001 |
|
8 |
Shift << 1 |
1010 |
0000 0001 0001 0010 |
Rem < 0, Rem = Rem - Div |
1010 |
1111 0111 0001 0010 |
|
Rem < 0, do nothing |
1010 |
1111 0111 0001 0010 |
|
9 |
Rem = Rem + Div |
1010 |
0000 0001 0001 0010 |
Final result is quotient 0001 0010b = 18 remainder 0000_0001b = 1
Problem 3
Answer the following questions for the floating-point number system:
12-bit format with the MSB (bit 11) being a sign bit
5-bit exponent (bits 10-6), which is stored in excess-16 format
6-bit normalized mantissa (bits 5-0) with base 2
(a) What does "normalized" mean in this context?
The leading bit of the mantissa cannot be “0”. This means that the mantissa must have a value between 1 and 2, not including 2.
(b) Represent the following numbers in the given format
1.5 = 0 10000 100000
-0.305 = 1 01110 001110
63 = 0 10101 111110
1/32 = 0 01011 000000
(c) The smallest normalized positive number is :
0 00000 000001 (1) * 2^(-22)
Note: 0 00000 000000 is reserved for zero. If the exponent is 0, the result is denormalized
The largest normalized positive number is
0 11110 11 11 11 (1+1/2+1/4+1/8+1/16+1/32+1/64) * 2^14 = 127 * 2^8
Note: an exponent of 11111 is reserved for NaN and infinity based on the mantissa.
(d) Subtract, multiply, and divide the following: (show all steps)
A = 0 10101 010001
B = 1 01100 101110
Subtract: exponent: 5 - (-4) = 9
Shift B right 9 bits then A+(-B) = 1..01000100.....
Result: 0 10101 010001
Multiply: exponent 10101 + 01100 – 10000 = 10001
Multiply mantissas = 10.001011001110
Normalize and round: result = 1 10010 000110
Division: exponent 10101 – 01100 + 10000 = 11001
Divide mantissas = 0.101111001
Normalize and round: result = 1 11000 011110
Problem 4
(a) Create a table with all 16 combinations of data bits encoded with their check bits. Hamming code (m = 4, k = 3)
|
C1 |
C2 |
B1 |
C3 |
B2 |
B3 |
B4 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
0 |
2 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
3 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
4 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
5 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
6 |
1 |
1 |
0 |
0 |
1 |
1 |
0 |
7 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
8 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
9 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
10 |
0 |
1 |
0 |
0 |
1 |
0 |
1 |
11 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
12 |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
13 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
14 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
15 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
(b) If the 7 bits read from a memory using this encoding are as given in each case below, compute the correct data bits, assuming that no more
than a single error has occurred in each.
Initial code correct code
c1 c2 b1 c3 b2 b3 b4 c1’ c2’ c3’ s3 s2 s1 c1 c2 b1 c3 b2 b3 b4
1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 0 0 1 1
1 1 0 0 0 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0
1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 1
(c) Give an example of 7 bits of data that, if read from this memory, would appear to be correct but in fact are in error. Explain why your
answer fits this description.
|
C1 |
C2 |
B1 |
C3 |
B2 |
B3 |
B4 |
Code 1 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
Code 2 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
Suppose code 1 is the correct code, code 2 is has 3 bit error at c1, c2 and b1. However, we can not detect a error at all by re-compute the parity.
Because to detect a 3-bit error, the hamming distance has to be at least 4,
The hamming distance of above code is 3, it can not detect 3 bit errors.
Problem 5
7.35 from the textbook
Pages are 4KB and page table entries are 4B, so 1K page table entries can fit on a page => 10 bits are needed for the page table offset. Since pages are 4KB, the page offset needs to be 12 bits. This leaves 32 - 10 - 12 = 10 bits left for the page table number field.
Page table number: bits 31 - 22
Page table offset: bits 21 - 12
Page offset: bits 11 - 0
A program needs to store the first level of the page table in memory, pointed to by the page table number field = 10 bits. 2^10 * 4B per entry = 4KB needed in memory.
Problem 6
7.36 from the textbook
From previous question: 2nd-level page table is
paged, and 1K entries fit on a page. 1/2 of the entries are valid => 512 valid entries. Each
valid entry points to a page in memory (4KB).
Bytes of virtual address space in memory = 512 * 4KB (valid entries) + 4KB (first-level page
table) + 4KB (second level page table) ~= 2MB.