1
\$\begingroup\$

Pretty simple question. Does an ALU internally always do multiple operations like add, sub, div, mul, ... and you simply have to specify which result you want to return? I was told that it does that, but I wasn't able to find proof of that being correct. Though I found some graphics containing a multiplexer which from my understanding has basically one output and multiple inputs and by setting some special inputs you can pipe on input to the output. So that might be it, but I don't know enough about that to fully understand it.

I'm specifically wondering about the 8085 architecture's ALU in case it is special, but I'd also like to know about other ALUs if there are different ones.

\$\endgroup\$
  • 1
    \$\begingroup\$ It will certainly depend on the ALU, I have seen some that do it and some that don't. No idea about the 8085 in specific \$\endgroup\$ – PlasmaHH Jan 12 '16 at 13:31
  • \$\begingroup\$ Thank you, can you link me one that does it or maybe give me a name? \$\endgroup\$ – Forivin Jan 12 '16 at 13:34
  • 1
    \$\begingroup\$ Subtraction can use the same hardware as addition, but where you xor all bits of the value you are subtracting with 1, and set the carry in flag. \$\endgroup\$ – Tom Carpenter Jan 12 '16 at 13:46
  • 1
    \$\begingroup\$ Look up the age of the 8085. It dates from the era when every part of a circuit was hand optimised, and hand layout with tape and razor blade was still common (though likely Intel was using CAD systems). So it would have been designed to aggressively minimize the number of gates used. And as Tom says, you can add and subtract using the same circuit with a little care - so I think that gives you your answer. \$\endgroup\$ – Brian Drummond Jan 12 '16 at 13:50
  • \$\begingroup\$ Can you see a way to produce multiple results (for example add and subtract) simultaneously, and select the correct answer with the fewer gates (or transistors) than logic producing only one result? I think @BrianDrummond has described an approach (an algorithm with a clear objective function to optimise) to answer the question. (Maybe Brian could convert the comment to an answer, so folks can upvote it?) \$\endgroup\$ – gbulmer Jan 12 '16 at 14:08
2
\$\begingroup\$

Look up the age of the 8085. It dates from the era when every part of a circuit was hand optimised, and hand layout with tape and razor blade was still common (though likely Intel was using CAD systems). So it would have been designed to aggressively minimize the number of gates used. And as Tom says, you can add and subtract using the same circuit with a little care - so I think that gives you your answer.

From GBulmer's comment:

Can you see a way to produce multiple results (for example add and subtract) simultaneously, and select the correct answer with the fewer gates (or transistors) than logic producing only one result?

Personally, I can't. If you produce both answers, you need additional logic in the form of multiplexers to select the one you want.

Now I'm not going to run the experiment, but I suspect that if you write an ALU in VHDL, which follows this approach, a modern synthesis tool will spend a very long time (several seconds) and optimise it down to something close to the hand-optimised version.

To test this hypothesis, generate A+B, A-B, and a 2:1 multiplexer as separate modules, synthesise them separately and note resources. Then roll them up into a single design and re-run synthesis (you may need to enable optimisations, "optimise for area" and "flatten hierarchy"). The latter will be smaller : how close it is to a hand-minimised version I don't know : the challenge is set if anyone wants to add another answer!

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ There are specialized structures in fast adders for FPUs for generating simultaneously A+B and |A-B|, there are also adders for calculating in parallel R+1 or R+2 for rounding. \$\endgroup\$ – TEMLIB Mar 23 '17 at 23:11
2
\$\begingroup\$

The 8085's ALU does only the operation you ask for, using a somewhat inscrutable collection of gates. In particular, the 8085 (and all the other processors I've reverse engineered) perform subtraction using 2's complement addition. That is, they invert the second argument and then perform addition on it. It would be kind of strange to use separate circuits for addition and subtraction.

To answer your more general question, most of the early processors I've looked at (4004, 8008, 8085, Z-80, ARM1) do not use multiplexers to select the ALU operation, but perform only the desired operation. One exception is the 6502, which uses a multiplexer to select between AND, XOR, shift-right, OR, and SUM. (Shift-left, subtract, and compare are done using SUM.)

For more than you wanted to know about the 8085 ALU, see my article. Here's a diagram showing one bit of the 8085's ALU circuitry. Note the multiplexer up front (i.e. at the bottom) that selects either argument X (for addition) or negated argument X (for subtraction). The blobs of gates in the middle perform AND, OR, XOR or SUM based on the select_op1 and select_op2 inputs. Note that only one operation is performed.

8085 ALU logic

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

There are different instructions in an 8085 instruction set for 8-bit adds and subtracts (and none for multiply- it's a very primitive processor). There is only one byte-wide result (plus some flags) for such operations.

If you are defining your own ALU you can certainly make it do whatever you like, within the resources of whatever is implementing it (an FPGA or whatever), but there is little need of such things in most small processors. Offhand I can't think of one that provides multiple answers at once (not counting say multiplies that have a wider result than the operands), however there are certainly ones that perform multiple operations- such as the multiply-accumulate (a multiply of two numbers, followed by an add of the results to another register) operation that is often used in filter implementations.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Okay, so the 8085 can't do multiplication, but it can do add and sub, right? Do both of these always happen inside of the ALU when you do either an add or a sub? \$\endgroup\$ – Forivin Jan 12 '16 at 13:51
  • \$\begingroup\$ No, only the operation requested by the op-code. If you look up the function of an ALU slice such as a 74181 you will see more-or-less what the gates and registers look like in a processor of that era. \$\endgroup\$ – Spehro Pefhany Jan 12 '16 at 15:46
1
\$\begingroup\$

I can't give you details on the 8085 architecture, but in general it does not make sense to have all functions implemented in parallel. For example, take a simple ALU that has ADD, SUB and NEG instructions only. Also note that the subtraction A - B is nothing else than adding the negated value of B: A - B = A + (-B). That means, addition and subtraction can be done in the same adder circuit, just by activating a negation logic in front of one of the inputs. Next, the same negation logic can be used for the NEG instruction, by forcing A = 0. In total, this ALU just needs one adder and one negation to fulfill all three operations, thus saving expensive space on the silicon die.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

This is very implementation specific, but usually not correct.

An ALU subtract ( X - Y ) in a typical implementation is as follows: -Two's complement calculation performed on the second number ( Y ), giving ( -Y ) -Addition of the the first number and the twos complement output ( X + ( - Y ) )

Some implementations will have a subtraction unit in addition to the main addition unit, but it is more common to have a single addition unit that is used for both addition and subtraction.

Multiplication and Division are more complex, but fundamentally have some overlapping functionality, so many implementations will have one unit capable of doing either.

| improve this answer | |
\$\endgroup\$

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.