Electronic – the reasoning for the arithmetic functions on the 74181

digital-logic

I don't understand why the 74181 operates the way it does. It does provide the full set of logic functionality (AND, NAND, OR, NOR, XOR, shift),but its arithmetic functionalities are not so clear. For example, it does not contain A - B and A + B in the same mode.

Could you provide some history background about how it was designed?

Best Answer

I know this is an old question, but I recently reverse-engineered the 74181 and can explain in detail why it has the functions it does.

The 74181 is a 4-bit ALU chip that provides 16 logic functions and 16 arithmetic functions on its operands A and B. Many of the logic functions are what you might expect (AND, OR, XOR), but there are also unusual ones like A OR NOT B. The arithmetic functions are even stranger. While you have A PLUS B, and A MINUS B, some such as (A OR B) PLUS (A AND NOT B) seem pretty random.

There's actually a reason for this set of operations. The logic functions provide all 16 Boolean functions f(A,B). The arithmetic functions all boil down to A PLUS f(A,B) PLUS carry-in.

Step back to see why there are 16 functions. If you have a Boolean function f(A,B) on one-bit inputs, there are 4 rows in the truth table. Each row can output 0 or 1. So there are 2^4 = 16 possible functions. Extend these to 4 bits, and these are exactly the 16 logic functions of the 74181, from trivial 0 and 1 to expected logic like A AND B to contrived operations like NOT A AND B.

The arithmetic functions are simply these 16 functions added to A with the carry-in added. For example, If f(A,B)=B, you get A PLUS B PLUS carry-in. If f(A,B) = NOT B, you get A PLUS NOT B PLUS carry-in, which in two's-complement logic turns into A MINUS B MINUS 1 PLUS carry-in.

Other arithmetic functions take a bit more analysis. Suppose f(A,B) = NOT (A OR B). Then each bit of A PLUS f(A,B) will always be 1 except in the case where A is 0 and B is 1. So the result is A OR NOT B. Even though you're doing addition, the result is a logical function. The other strange arithmetic functions can be explained similarly.

One thing to note is A PLUS A gives you left shift, but there's no way to do right shift on the 74181.

In its implementation the 74181 has four select lines that pick which of the 16 f(A,B) functions are used. The first half of the chip's circuitry computes the four 1-bit sums of A with f(A,B). (Specifically it is creating the Generate and Propagate signals that are used for carry lookahead. This lets the 74181 work in parallel, rather than using a ripple carry.) The second half of the chip's circuitry generates all the carries in parallel and computes the final sum.

Internally, the logic functions are implemented by performing addition with the internal carries all forced high by the M line: A PLUS f(A,B) with all carries. It's straightforward to see that this still generates 16 unique logical functions. However, it permutes the order, which is why if you look at the datasheet there's no obvious connection between the logic functions and the arithmetic functions.

If you want to understand the 74181's internals, first look at the 7483 4-bit adder, which came out two years earlier. It uses the same carry computation techniques, but is simpler to understand as it provides one function, not 32. You can think of the 74181 as the generalization of the 7483.