I am new to VHDL, working on assignment for my Computer architecture class:

implement 32 bit ALU using VHDL, that performs only certain operations: and, shift left, shift right, complementing one of the input, rest of operations will do simple addition. Trick is, code needs to be structured, since instructor provided bitshifter and adder.

I have googled for examples, but all of them use straightforward code(such as result <= a + b). What would be a good way to implement ALU using above requirements ???
Thanks !

  • \$\begingroup\$ Mux the inputs and the outputs to the provided cores or separate processes that do each function? \$\endgroup\$ Nov 6, 2012 at 22:44

3 Answers 3


If the bitshifter and adder are already provided for you, it seems all you have left to do is connect them together. Build a module that directs the proper inputs given a control signal. If you have six possible operations you'll need at least three bits for a control signal, right? You might want to choose the various operations to have a similar bit in common, and you can use that bit to mux the outputs from each component block to the output of the block you're building. I'm going to use some pseudo code because, first, this is your homework and, second, I haven't written VHDL in years.

  case control_signal is
    when 1 =>   -- Control=1 means add inputs
      adder_input_A <= top_level_input_A;  -- Move inputs of top lever to the adder
      adder_input_B <= top_level_input_B;
    when 2 =>   -- Control=2 means shift the bits left
      bit_shift_input <= top_level_input_A;  -- Move input to bitshift block
      bit_shift_value <= top_level_shift;    -- This one can more likely be always connected
    when 3 =>
      do another one, like shift right
    when others =>
  end case;

So, it's you're basically creating a mux that switches the inputs depending on the operation being performed. Obviously, I have no idea what your current blocks look like and how they're implemented, but I think the general concept should still apply.

  • 1
    \$\begingroup\$ Why on earth would you switch the inputs? It's the outputs of the various sub-functions you want to select from. \$\endgroup\$
    – Dave Tweed
    Nov 7, 2012 at 4:31
  • \$\begingroup\$ Yes, you're right, but really I think it could work either way. The asker has already been given the sub blocks, either they tie the inputs together (which is what I assume you're suggesting) or they switch between them, then for the last part of both solutions, switching the outputs, we already agree on. However, this is clearly not my specific area of expertise, so if it's yours, I'll gladly interpret your question/statement as me being wrong and I'd urge you to submit the correct answer. \$\endgroup\$
    – Samuel
    Nov 7, 2012 at 11:34
  • 1
    \$\begingroup\$ @DaveTweed, yes, that's a counter-intuitive thing about arithmetic logic extenders. We switch the inputs because we end up with fewer gates and lower power consumption that way. The adder is a fairly large component gate-wise, so we want to minimize how many of them we use. If we switched after the adder, then each function that used addition would need its own adder. Putting the extra function logic ahead of the adder, even to the extent of doing the entire operation and setting one of the addends to 0, means we just need one adder. \$\endgroup\$
    – Theran
    Nov 7, 2012 at 18:08
  • \$\begingroup\$ It should also be warned that the example code as written would synthesize with implicit latches rather than the desired muxes, because not every case assigns a value to each component input. \$\endgroup\$
    – Theran
    Nov 7, 2012 at 18:18
  • \$\begingroup\$ @DaveTweed you can mux the inputs or outputs; I typically OR all my outputs together and make sure the core outputs zeroes when not selected. \$\endgroup\$
    – akohlsmith
    Dec 2, 2012 at 19:24

You need to build up the various operations from addition and other lower level ones. For example in elementary school we learned how to do multiplication of multi-digit numbers from single digit numbers. In binary multiplication is either by 1 or 0, which is either take the input as-is or output a zero. Repeat this for the LSB of one multiplicand, then shift and repeat.


Send the inputs to the cores you have been provided. You may also need some additional control signals (your bit shifter may have a 2-s complement shift amount, or separate "number of bits" and direction signals for example).

Choose (ie use a mux to select) which of your cores to send to the output signal.

  • \$\begingroup\$ I realize that MUX is the way to go, but how to set Mux, if I chose to use case statement ? \$\endgroup\$
    – newprint
    Nov 7, 2012 at 18:42
  • \$\begingroup\$ I think you have it - use a case statement with the "instruction" as the selector and for each case write the value from the appropriate block to the output signal \$\endgroup\$ Nov 8, 2012 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.