Building an ALU
Notes
- This is from appendix A.5 and chapter 4.
- We built an one bit adder in Logic and Switching
- Cout = ab + aCin + bCin
- S = a b Cin + a b Cin + a b Cin + abCin
- This leads to the three input/two output 1 bit adder
- a, b, Cin
- sum, Cout
- And we learned that we can perform subtraction by inverting b and setting the cary in to be 1.
-
- We have seen that we need and and or
- So we can extend this idea with a two bit control line.
-
- Note: I have separated the cin and B_invert lines,
- We will want to invert all of the b values, not just the first and those with carry.
- At this point we have
- Two different control lines:
- Operation (OP)
-
Op Action 00 and 01 or 10 binvert Op 0 + 1 - 11 unused
-
- Binvert
- No impact on and/or
- Selects addition or subtraction
- Leg uses a nor as well.
- DeMorgan tells us that a·b = a + b
- So if we add an ainvert like b_sub
, we can accomplish this. Op Action 00 ainvertbinvert Op 00 and 11 nor 01 or 10 binvert Op 0 + 1 - 11 unused
- Not, we can also get nand, OP = 01, ainvert = 1, , binvert = 1
- We can hook a bunch of these together to form a 32/64 bit alu.
- Operation 3 could be less
- Subtract, if the result is negative the first is less than the second.
- We can detect this by looking at the sign of the MSB
- But we want the adder to produce a 1 on less than.
- So we do the following
- Add a less input line to our our one bit ALU
- When we build a 32/64 bit ALU take the sum bit from bit 31/63 and pipe into the less input to ALU 0
- Connect less to the unused input to the mux.
- Connect 0 to all other less inputs.
- So op = 11, binvert =1, cin0 = 1, will produce less
-
- Zooming out a bit, we also need to tell if the entire sum is 0
- For the conditional branch instructions can add a zero.
- This is just and nor of all the sum bits.
- Finally they add an overflow detection unit to ALU31
- This just looks at the carry in, carry out of this ALU
- If they match, no problem
- If they don't match, overflow.
- See page A-35 of the book.
- Look at the picture
- They present this table:
- For the table
- ALU Control Lines: ABCC
- A - ainvert
- B - binvert
- CC - operation
ALU Control Lines Function 0000 AND 0001 OR 0010 ADD 0110 SUBTRACT 0111 Set on Less 1100 NOR - ALU Control Lines: ABCC
- Ok, so I developed this from appendix A.
- But looking back to chapter 4, they did something different with ALUOP 11
- They want it to be PASS Input B
- This is for the Conditional branch instructions.
- Note, these send register B as the second input to the ALU
- And we just want to check to see if it is zero or not.
- So ALUOP= 11 just pushes the bits for b to the output
- Which will be ored together to produce a zero or not zero.
- In other words, wire b to less.
- Why b? (Look at the green card)
- SLT is a MIPS instuction.
- The digital file.