The MIPS AUL
This is material from B.5
We need an ALU to add and subtract.
I know you have built a ripple carry adder, but we will take a different approach.
They observe that a half adder can be reduced to
c
out
= a·c
in
+ b·c
in
+ a·b
sum = a
bc
in
+
a
b
c
in
+
ab
c
in
+ abc
in
This is a bit strange, but they proceed to build a 1 bit ALU.
We need an and and an or.
Which then requires us to provide a control line to select which output we are interested in.
So we can hook these together to form a (4 bit) ALU.
Show how to and, or , add two numbers with
this
circuit.
This will do for addition but what about subtraction.
Subtraction is just addition by a negative of the number.
We can take the negative of the number by inverting and adding 1.
So the following change is in order:
Do a subtract using
this circuit
.
Set B_Invert to 1
Set Carry_In to 1.
We need a bitwise NOR, which we can form by
a+b
=
a
·
b
So we need to an an a_invert line, and MUX.
Next we need to deal with the branch conditions.
stl $s1, $s2, $s3
R[rd] = (R[rs] < R[rt]) ? 0: 1
If R[rs] < R[rt] then R[rd] is set to 1.
We can just subtract R[rt] form R[rs]
-3 -(-2) = -1 (the first is smaller)
7-8 = -1 (the first is smaller)
-5 - (-6) = 1 (the second is smaller)
4-3 = 1 (the second is smaller)
li $t0, n li $t1, m slt $t2, $t1, $t2
So the sign of the result is 1 is the value we wish to store in the destination register.
So this is the value we would like to be able to produce from the ALU.
We will create a new 1 bit alu, ALU0
Add a new operation (3)
It is the same as the other ALUs, but
Add a new input to ALU0 type called less.
This is piped directly to the third output port on the MUX.
This needs to be fed the MSB of the sum.
So we need a new 1 bit ALU for the end of the computation as well.
Add an output that is the result of the MSB of a sum.
This gets wired to the less port of ALU0.
The final is
here
One last bit... BEQ, BNE
This is a subtraction.
If A-B = 0, then there is an equal.
So we need a way to see if all the bits are 0.
We can just do a subtraction and put all the result bits into a big OR.
How do we AND two numbers?
Place the numbers on A and B
Set the Operation to be 0
Set A_invert and B_invert to 0
Set Carry_In to be 0
How do we OR two numbers?
Place the numbers on A and B
Set the Operation to be 1
Set A_invert and B_invert to 0
Set Carry_In to be 0
How do we NOR two numbers?
Place the numbers on A and B
Set the Operation to be 0
Set A_invert and B_invert to 1
Set Carry_In to be 0
How do we add two numbers?
Place the numbers on A and B
Set the Operation to be 2
Set A_invert and B_invert to be 0
Set Carry_In to be 0
How do we subtract two numbers?
Place the numbers on A and B
Set the Operation to be 2
Set A_invert to 0
Set B_invert to be 1
Set Carry_In to be 1
How do we slt?
Place the numbers on A and B
Set the Operation to be 3
Set A_invert to 0
Set B_invert to be 1
Set Carry_In to be 1