Mips Alu
Mips Alu
Mips Alu
In MIPS, the ALU takes two 32-bit inputs and produces one 32-bit output, plus some additional signals Add is only one of the functions, and in this lecture, we are going to see how an full ALU is designed
ALU
Review
1-bit full adder
32-bit adder
Or
a b Or result
Subtraction?
How to implement subtraction?
Subtraction
Using twos complement representation, we can implement subtraction through addition The reason is that a negative number -b in 2s complement is actually 2n-b. So if you do a+2n-b and take only the lower n bits, it becomes a-b because 2n is a one bit at bit n (bit indices are 0,1,2,, n-1, n). What do we need to add to the ALU we have in order to be able to perform subtraction?
11
12
Subtraction
Notice that every time we want the ALU to subtract, we set both CarryIn and Binvert to 1. For add or logical operations, we want both control lines to be 0. We can therefore simplify control of the ALU by combining the CarryIn and Binvert to a single control line called Bnegate.
14
Complication
If we only use the sign bit of the adder, sometimes we will be wrong
For the following example (using 4 bits only), we have
Overflow
The problem is that sometimes we have overflow.
If we have only 4 bits, a number greater than 7 or a number less than -8 will cause an overflow because it cannot be represented in 4 bits. In the previous example, -7-6=-13, overflowed.
Overflow Detection
One way to detect overflow is to check whether the sign bit is consistent with the sign of the inputs when the two inputs are of the same sign if you added two positive numbers and got a negative number, something is wrong, and vice versa.
19
Overflow Detection
So, we can detect the overflow by checking if the CarryIn and CarryOut of the most significant bit are different
22
Overflow
The sign bit is correct if there is no overflow If there is overflow, the sign bit will be wrong and needs to be inverted
23
24
26
ALU Symbol
27