Académique Documents
Professionnel Documents
Culture Documents
Operation
CarryIn
1
1
Result
b
1
Less
3
Set
Overflow
detection
Overflow
Sign
B
Carry
In
Carry
Out
Sign of
Result
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
0
1
0
1
1
1
0
1
1
0
1
0
0
1
Correct
Sign of
Result
0
0
1
0
1
0
1
1
Overflow
?
No
Yes
No
No
No
No
Yes
No
Carry In
XOR
Carry Out
0
1
0
0
0
0
1
0
Notes
Carries differ
|A| < |B|
|A| > |B|
|A| > |B|
|A| < |B|
Carries differ
From this table an Exclusive OR (XOR) of the CarryIn and CarryOut of the sign bit serves to detect
overflow. When the signs of A and B differ, the correct sign of result is determined by the relative
magnitudes of A and B, as listed in the Notes column.
Problem (3)
When operating normally, the ALU does subtraction based on the equation:
A B = A + (B)
In those cases, the CarryIn is set to 1 as part of the computation of B. Since the malfunction causes
CarryIn to be 0, the result for subtraction will always be one less than it should be. Specifically, instead of
computing A B, the ALU will compute A B 1.
A user/programmer will observe incorrect results for all instructions that require the ALU to perform
subtraction. Specifically:
A) The sub instruction will compute Rs Rt 1 instead of Rs Rt.
B) The beq instruction will branch whenever Rs = = Rt + 1 instead of whenever Rs = = Rt.
C) The slt instruction will set Rd to 1 whenever Rs < Rt + 1 instead of whenever Rs < Rt.
Solutions to Homework #2
Problem (4)
A OR B
With control lines set to 0101, the Binvert input to the ALU would be set and the output of the OR
gates is selected as the result.
Problem (5)
The only change will be on the result from the slt instruction. Specifically, instead of generating
00000000 or 00000001 as the comparison result, the instruction will generate 00001000 or
00001001, respectively.
Solutions to Homework #2
Problem (6)
A modular 1-bit adder:
Cin
Cout
Y
0
0
1
1
0
0
1
1
Cin
0
1
0
1
0
1
0
1
S
0
1
1
0
1
0
0
1
Cout
0
0
0
1
0
1
1
1
0
1
YCin
00
0
1
01
1
0
11
0
1
10
1
0
YCin
00
0
0
0
1
01
0
1
11
1
1
10
0
1
Cout
X
Cin
X
Y
Cin
X
Y
Cin
X
Y
Cin
X
Y
Cin
4-bit adder:
X3
Y3
X2
Y2
X1
Y1
X0
Y0
Cout
Cin
S3
S2
S1
S0
Problem (7)
1 1 1 1
Y
4-bit Adder
Cin
CLK
OUTPUT
Problem (8)
In binary numbers multiplication by 2 can be accomplished by a left shift of 1 bit if ignoring any
overflow. Multiplication by 5 is the same as a multiplication by 4 (left shift of 2 bits) followed
by an addition of the multiplicand itself. In MIPS:
sll
add
Address
10000000
10000100
$17, $16, 2
$17, $16, $17
Op
000000
000000
Rs
00000
10000
# $17 = 4 * $16
# $17 = $17 + $16
Rt
10000
10001
Rd
10001
10001
Shamt
00010
00000
Func
000000
100000
Inst
sll
add