0
\$\begingroup\$

Currently I am reading up on some documentation on the Zilog Z80 instruction set. There are a few instructions that has one operand that involves the Accumulator, which is denoted as an 'A' in the data sheet, and another operand that takes any of the registers within the CPU. For the purposes of asking this question, I will only focus on the "ADD A, r" instruction.

As taken from one of the Zilog Z80 datasheets, this is what is presented on the instruction:

enter image description here

As seen from the possible registers that can be chosen, register 'A' is one of them.

Register 'A' is also the Accumulator as given here:

enter image description here

My question is, how is it possible to put both operands as the Accumulator? One thing I should also clarify is that there are other instructions that have this same kind of situation.

\$\endgroup\$
  • \$\begingroup\$ What is the problem? You can calculate X + Y, why not X + X? Note that in some cases (SUB, XOR, AND, OR) the result will be predictable (independent of the value), which makes the instruction less useful. \$\endgroup\$ – Wouter van Ooijen May 12 '14 at 5:42
  • \$\begingroup\$ I was just looking for some clarification. My untrained eye seems to find it unusual to essentially have the same thing for both operands. On the other hand I was thinking the same thing that it does make the instruction less useful, if not redundant. \$\endgroup\$ – jrcatbagan May 12 '14 at 6:50
  • \$\begingroup\$ Seems to me, we used to OR A,A in order to test bits and set flags without altering A. \$\endgroup\$ – gbarry May 12 '14 at 7:11
  • \$\begingroup\$ The Z80 had some unofficial instruction sets that allowed register pairs to be used as Accumulators (16 bit) and other nifty stuff. The refresh register if used right, was a good source for random numbers. It's hard for me to remember, getting older all the time. \$\endgroup\$ – Optionparty May 12 '14 at 17:22
  • \$\begingroup\$ Also, XOR A, A cleared the register in one instruction fetch. \$\endgroup\$ – casualuser May 13 '14 at 2:35
1
\$\begingroup\$

The ADD A,A instruction is many times seen being used to multiply the value in A by 2. It can also be viewed as a "shift A left by one".

The ALU of the microprocessor will have multiplexers that are used to select the sources for the OP1 and OP2 sides. These MUXes have enough inputs to allow all possible sources to be selected and fed to the ALU inputs. There is certainly nothing to have prevented the designer from connecting the output side of the A register to one set of inputs on the OP1 MUX and to another set of inputs on the OP2 MUX.

\$\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.