Electronic – Designing a 4-bit ALU to compute various functions

aluasicdigital-logic

I've been working on designing an ALU that calculates various functions but I don't really know how to separate each function from one another. The inputs are 4-bit numbers A and B. I have a decoder that selects which function to use, but I don't know how to implement the functions from the decoder. The ALU needs to do arithmetic operations and also logical operations. If anyone knows how to go about structuring an ALU that has 2 4-bit inputs and 1 4-bit output, any guidance would be appreciated. Thanks.

Best Answer

In terms of "separating" the functions, that's not really how digital logic works. Digital logic is "always doing everything". You need a mux (multiplexer) in there. The multiplexer is used to pick the right output from all of those generated.

Assume inputs A and B, output Q. Assume the ALU does two different things: Q=A+B, or Q=A&B.

The ALU will have an adder. It will also have a big AND gate.

A and B both go to the adder, and the AND gate. Always. Every moment of every day, the adder is adding A and B, and the gate is ANDing A and B.

The mux is used to select which one of the outputs we want to pass to Q. If the control signals to the ALU say "add", then the mux will select the output of the adder and pass it to Q; the output of the AND gate is unused. If the control says "and", the mux will select the output of the AND gate and pass it to Q instead, while the output of the adder is unused.

Imagine A = 0b0001 and B = 0b0010 on the inputs of the ALU. The adder is always producing 0b0011, and the AND gate is always producing 0b0000. If you provide the "add" control signal, the 0b0011 is passed to Q. You can leave A and B alone, and change the control signal to "and", then 0b0000 is passed to Q.