π Friday, April 26th, 2024
The secret of success is constancy to purpose.
β Benjamin Disraeli
ECS154A Lecture: 8-op ALU design
Design an ALU, given the following operations: add, sub, mul2 (multiply by 2), not, xor, and, or.
Notice how we can implement add & sub & mul2 together, and implement not & xor together, so only four mux inputs are needed
0 | add | 000 | x | 00 | 0 | x | 0 |
1 | sub | 001 | x | 00 | 1 | 1 | 1 |
2 | mul2 | 010 | x | 00 | 1 | 0 | 0 |
3 | - | 011 | x | xx | x | x | x |
4 | not | 100 | 1 | 11 | x | x | x |
5 | xor | 101 | 0 | 11 | x | x | x |
6 | and | 110 | x | 01 | x | x | x |
7 | or | 111 | x | 10 | x | x | x |
Note that for subtraction, we are taking the twoβs complement of B, but we donβt add 1 to the ~B immediately; we add the one as a carry-in () in the full adder.
Now that weβre done with the actual calculation, we need to design the ALU controller.
ECS154A Discussion: 8-op ALU controller
K-map for :
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | x | x | x | x |
1 | 1 | 0 | x | x |
We can make a group of four (column 00 and column 10) thanks to the three donβt cares which we can pretend are just ones.
K-map for
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | 0 | 0 | x | 0 |
1 | 1 | 1 | 0 | 1 |
We canβt really simplify much here. We can go with a two-element group that wraps around (op = 100, 110), and then overlap that with another two-element group (op = 100, 101). |
K-map for
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | 0 | 0 | x | 0 |
1 | 1 | 1 | 1 | 0 |
K-map for
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | 0 | 1 | x | 1 |
1 | x | x | x | x |
Using the donβt cares, we can form two four-element groups (columns 01 & 11, and columns 11 & 10).
K-map for
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | x | 1 | x | 0 |
1 | x | x | x | x |
K-map for
\ | 00 | 01 | 11 | 10 |
---|---|---|---|---|
0 | 0 | 1 | x | 0 |
1 | x | x | x | x |
It turns out that:
We need to find a way to save the ALU flags and prevent some of them from changing when they are not supposed to (e.g., the carry flag shouldnβt be changed on any logic operation). In other words, we need to decide, using , if we want to pass the new flags into the actual flag registers.
0 | add | 000 | 1 | 1 | 1 | 1 |
1 | sub | 001 | 1 | 1 | 1 | 1 |
2 | mul2 | 010 | 1 | 1 | 1 | 1 |
3 | - | 011 | x | x | x | x |
4 | not | 100 | 0 | 0 | 1 | 1 |
5 | xor | 101 | 0 | 0 | 1 | 1 |
6 | and | 110 | 0 | 0 | 1 | 1 |
7 | or | 111 | 0 | 0 | 1 | 1 |
Note that and . We can define . When , we want to prevent V & C from being saved; otherwise, we want to pass them to the actual registers. For now, saving to registers wonβt be shown here (registers are covered next week). I think we need a slightly different design of the circuit when actual registers are involved, e.g., for a D flip-flop, we can use a mux that takes in and as inputs and as the select bit.
Expect around 6 operations for an ALU design question on the exam.