2012 Midterm Solutaion
2012 Midterm Solutaion
MIDTERM EXAMINATION
Name: _____________________________________________________
SID: __________________________________________
Signature:__________________________________________________
Closed book exam. All electronic devices including calculators are not allowed.
If in doubt how to interpret a question, make an assumption and elaborate your solution
based on this hypothesis. Explain all your assumptions and clearly define the symbols
used.
If you finish 10 minutes or less before the due time, remain seated until the end of the
exam.
Total (100)
1
Question 1
b. (4 pts) Convert the content of the register C to its equivalent decimal number. Show your
work in detail.
In 2’s complement representation:
C = 111 1111 0111 represents a negative number (say – c) since the msb, the sign bit = 1.
The magnitude of C, i.e., c = - (-c) = - C = 2’s complement (C) = 000 0000 1001 = 910
=> C = -9, which is confirmed by performing B-A in decimal
c. (4 pts) How would a computer detect an overflow in this operation? Justify your answer.
OFL = Cy12 XOR Cy11 = 0
or
OFL = if the operands have the same sign bit, but different from the result’s sign bit
d. (4pts) Compute D = A + B. Show your work in detail. The result is an 11-bit signed
number and is stored in an 11-bit register D. What is the content of D after the operation?
Carry: 0 1 0 0 0 0 0 1 1 1 0
A 0 1 0 0 0 0 0 1 1 1 1
B 0 1 0 0 0 0 0 0 1 1 0
D 1 0 0 0 0 0 1 0 1 0 1
e. (4pts) Convert the content of the register D to its equivalent decimal number. Show your
work in detail.
D = 100 0001 0101 represents a negative number (say – d) since the msb, the sign bit = 1.
The magnitude of D, i.e., d = - (-d) = - D = 2’s complement (D) = 011 1110 1011 =
011 1111 1111 – 000 0001 0100 = (210 -1) – (16+4) = 1023 – 20 = 1003
=> D = -1003 ≠ 1045 !!!
2
f. (6pts)
i. How would a computer detect an overflow in this operation (A+B)?
ii.Applying that reasoning to this case, would an overflow be detected? Justify your
answer.
YES. Some explanations in the line with the following would be OK
Carry: 0 1 0 0 0 0 0 1 1 1 0 Verification in decimal: !
A 0 1 0 0 0 0 0 1 1 1 1 =512+15= 527
B 0 1 0 0 0 0 0 0 1 1 0 512+4+2 = 518
D 1 0 0 0 0 0 1 0 1 0 1 = -1003 ≠ 1045 > 1023 Overflow
10 10
D’s range is [-2 , 2 -1] = [-1024, 1023], so 1045 cannot be represented by D.
R 1 0 0 1 1 1 0 0
R >> 1 1 0 0 1 1 1 0
b. Starting again from the initial number 10011100, determine the register value after an
arithmetic shift left, both in binary and decimal.
R 1 0 0 1 1 1 0 0
<< R 0 0 1 1 1 0 0 0
Shifting to the left is equivalent to multiplication with 2, which may create overflow.
If signed numbers => here changes the sign => BAD! OFL
If unsigned numbers, the shifted number is smaller than the initial value => BAD, OFL
3
Question 2
2.1 (6 points)
2.2 (6 points)
A digital computer has a common bus system for 16 registers of 32 bits each.
The bus is constructed with multiplexers.
b0
R1 b0
b1
R1 b1
b30 b0
R1 b30
b31
R1 15
R15 b1 b31
R1
b0
b30
R1 b1
b31 14
R14
b30
b0
R1 b31
b1
R1
b30 b0
R1 R1 1
b31 b1
R1 R1
b30
R1 0
b31
R0
4
S3‐S0
Question 3 (30 points)
Design a 3-bit multi-function register R (R2R1R0) whose operation is described in the following
table, where K1 and K0 are two control bits.
Use in your design JK flip flops, logic gates and any digital components (encoders, decoders,
multiplexers, etc.); draw a detailed diagram of the logic circuit of the multi-function register.
↑ 1 1 Decrement by 1
Characteristic Excitation
Table Table
J K Q(n) Q(n+1) Q(n) Q(n+1) J K Remember the generation of the FF excitation equations:
0 0 0 x 0 0 0 x Copy to J the next state Q(n+1) if Q(n)=0
0 1 1 x 0 1 1 x
1 0 x 1 1 0 x 1 Copy to K the complement of the next state Q(n+1) if Q(n)=1
1 1 x 0 1 1 x 0 J and K should be “x” otherwise
C1 C0 = 10 =>Increment by 3
Present State Next State FF Inputs
R2 (n) R1 (n) R0 (n) R2(n+1) R1(n+1) R0(n+1) J2 K2 J1 K1 J0 K0
0 0 0 0 1 1 0 x 1 x 1 x
0 0 1 1 0 0 1 x 0 x x 1
0 1 0 1 0 1 1 x x 1 1 x
0 1 1 1 1 0 1 x x 0 x 1
1 0 0 1 1 1 x 0 1 x 1 x
1 0 1 0 0 0 x 1 0 x x 1
1 1 0 0 0 1 x 1 x 1 1 x
1 1 1 0 1 0 x 1 x 0 x 1
5
J2 K2
R1 R0 00 01 11 10 R1 R0 00 01 11 10 J2 = K2 = R0 + R1
R2 R2
0 0 1 1 1 0 x x x x J1 = K1 = R0’
1 x x x x 1 0 1 1 1 J0 = K0 =1
C1 C0 = 11 =>Decrement by 1
Present State Next State FF Inputs
R2 (n) R1 (n) R0 (n) R2(n+1) R1(n+1) R0(n+1) J2 K2 J1 K1 J0 K0
0 0 0 1 1 1 1 x 1 x 1 x
0 0 1 0 0 0 0 x 0 x x 1
0 1 0 0 0 1 0 x x 1 1 x
0 1 1 0 1 0 0 x x 0 x 1
1 0 0 0 1 1 x 1 1 x 1 x
1 0 1 1 0 0 x 0 0 x x 1
1 1 0 1 0 1 x 0 x 1 1 x
1 1 1 1 1 0 x 0 x 0 x 1
J2 K2
R1 R0 00 01 11 10 R1 R0 00 01 11 10 J2 = K2 = R0’ R1’ = (R0 + R1)’
R2 R2
0 1 0 0 0 0 x x x x J1 = K1 = R0’
1 x x x x 1 1 0 0 0 J0 = K0 =1
Ri(n) Di Ri(n+1) Ji Ki
0 0 0 0 x
0 1 1 1 x
1 0 0 x 1
1 1 1 x 0
Ji = Ki = Di xor Ri or
Ji = Di ; Ki = D1’
or …
6
Conclusion
(T FF approach, i.e., J = K = T):
K1 K0 J2 = K2 J1 = K1 J0 = K0
0 0 0 0 0
0 1 D2 xor R2 D1 xor R1 D0 xor R0
1 0 R0 + R1 R0’ 1
1 1 R0‘ R1’ R0’ 1
Cout1 0
1 J Q
Σ1 2M R1
Cin1
3
U
D1 1
X K Q
Cout0 0
1 J Q
Σ0 2M R0
Cin0
3
U
0 X K Q
D0 1
7
Comprehensive description but longer approach:
8
Question 4 (20 points)
A 3-bit arithmetic circuit takes three control bits, x, y and z, and two 3-bit data inputs, A and
B. The operations supported by the arithmetic unit are described in the following table.
Draw a detailed logic diagram of the circuit using 1-bit full adders and the digital components of
your choice (encoders, decoders, multiplexers, etc.)
(Note: X’ is the 1’s complement of X)
xy z=0 z=1
00 F = A + B (add) F=A+B+1
01 F = A + B’ F = A - B (subtract)
10 F = A (transfer) F = A + 1 (increment)
11 F = A - 1 (decrement) F = A’ + 1 (2’s complement)
xy z= 0 z= 1
00 A3 A2 A1 A0 + B3 B2 B1 B0 + 0 A3 A2 A1 A0 + B3 B2 B1 B0 + 1
01 A3 A2 A1 A0 + B3’B2’B1’B0’+ 0 A3 A2 A1 A0 + B3’B2’B1’B0’+ 1
10 A3 A2 A1 A0 + 0 0 0 0 + 0 A3 A2 A1 A0 + 0 0 0 0 + 1
11 A3 A2 A1 A0 + 1 1 1 1 + 0 A’3A’2A’1A’0+ 0 0 0 0 + 1