Arithmetic Logic Unit (ALU)
An Arithmetic Logic Unit (ALU) is designed to provide basic mathematics and logical functions for a system. An ALU will provide these types of functions: add (with or without carry), subtract (with or without borrow), transfer the input to the output, increment the input by 1, decrement the input by 1, complement, AND, NAND, OR, NOR, and XOR.
Following is the logic diagram for a 74x181 ALU:
In the 74x181 ALU, two 4-bit numbers can be input at A0-A3 and B0-B3 (on the top of the IC). Additionally, a carry in bit can be applied to the CN' input. The M input determines the mode of the circuit: when true, the circuit performs logic functions (like AND or OR); when false, the circuit performs arithmetic functions (like A+B or A-B). The function of the ALU is controlled by S0-S3, as described below. The output of the circuit appears on Q0-Q3 (on the bottom of the IC), along with a carry out (CN+4) bit. Finally, if the function selected is to compare the two inputs, then output A=B will be true if the two inputs are equal. The G (Carry Generate) and P (Carry Propagate) outputs are used to cascade multiple ALUs.
Following is a partial truth table for the 74x181 ALU. Note, for simplicity, a second mode setting involving the carry bits is missing from this truth table; thus, there are many more functions available than implied by the table:
|S0||S1||S2||S3||Logic (M=H)||Arith (M=L)|
|H||L||L||L||(A+B)'||A + B|
|L||H||L||L||A'B||A + B'|
|H||H||L||L||Logical 0||minus 1|
|L||L||H||L||AB'||A plus AB'|
|H||L||H||L||B'||(A+B) plus AB'|
|L||H||H||L||A XOR B||A minus B minus 1|
|H||H||H||L||AB'||AB' minus 1|
|L||L||L||H||A'+B||A plus AB|
|H||L||L||H||(A XOR B)'||A plus B|
|L||H||L||H||B||(A + B') plus AB|
|H||H||L||H||AB||AB minus 1|
|L||L||H||H||Logical 1||A plus A'|
|H||L||H||H||A+B'||(A + B) plus A|
|L||H||H||H||A+B||(A + B') plus A|
|H||H||H||H||A||A minus 1|
An ALU is extremely versatile and can produce many different types of output from two input numbers. Using an ALU rather than coding with discreet gates saves the designer a great deal of time and effort.
ALU in Logisim
There is no built-in ALU in Logisim; however, a serviceable ALU can be constructed rather easily using the components that are available. The following circuit illustrates the beginning of an ALU in Logisim:
This 8-Bit ALU includes two inputs ("InA" and "InB") that are fed into four devices that provide both arithmetic (adder and subtracter) and logic (AND and OR) functions. While all four devices receive input data, the output from only one of these devices is selected by a multiplexer using the "Ctrl" signal; and that data are sent to the output ("Out") port. In the illustration, the Ctrl is 00, which selects the Add function. 00001111 ("InA") is added to 00000001 ("InB") and the output is 00010000. Additionally, most CPUs provide various single-bit outputs called "flags" to indicate some output value. Commonly, a "zero" flag is activated if the output of an operation is zero. That is easily provided by sending all of the output bits to an OR gate and then inverting the output of that gate. If all bits are low, the OR gate would output a low and the inverter would then output a high, which indicates that the original operation's output was zero.
Of course, a much more complex ALU is possible by expanding this basic concept.