6
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ good question, but I don't think any of us chiphacker users would know any of the TI motives beyond what is in the datasheet or on wikipedia en.wikipedia.org/wiki/74181 \$\endgroup\$ – Jason S Jan 18 '10 at 12:45
  • \$\begingroup\$ @Jason:thanks for your comment.then where is the good place to this question? \$\endgroup\$ – Jichao Jan 18 '10 at 14:09
  • \$\begingroup\$ not sure... check with a TI sales rep? perhaps they could put you in touch w/ one of the old-timers who worked on the 74181 back in the 1970's. \$\endgroup\$ – Jason S Jan 18 '10 at 22:55
7
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

A minus B minus 1 is used for subtraction, and the complement of the carry flag can be viewed as a borrow flag.

\$\endgroup\$
  • 1
    \$\begingroup\$ In fact even AVRs use this - they do not have an add immediate instruction (only substract immediate) since you can convert easily one into another. If both values are coming from registers then both sub and add are nice and fast but one is still not strictly necessary. \$\endgroup\$ – jpc Mar 21 '11 at 3:03
  • \$\begingroup\$ Yes, see stackoverflow.com/questions/1337831/… \$\endgroup\$ – starblue Mar 21 '11 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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