2

Accumulator register is a register that holds temporary values. Only EAX, AX, AL registers are accumulators.

As I know BX, CX, DX and extended versions can hold permanent values. So, why do we use EAX, AX, AL registers as accumulators?

What is an accumulator?

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
  • What do you mean by “permanent value?” – fuz Oct 25 '18 at 21:48
  • the results of arithmetic and logic operations that are not saved anywhere in memory – aizhan_maksatbek Oct 25 '18 at 21:49
  • But how are these values permanent? – fuz Oct 25 '18 at 21:51
  • @fuz I am sorry, not permanent :D temporary – aizhan_maksatbek Oct 25 '18 at 21:52
  • 3
    `ax` is called the accumulator register but it's really no different from the other general purpose registers `bx`, `cx`, `dx`, `si`, `di`, and `bp`. You can use any of them to hold any value you like. – fuz Oct 25 '18 at 21:58
  • ok :) and what actually accumulator is? Is that definition right for accumulator ? I am wondering why do we call AX as an accumulator? Is there any special case for AX? – aizhan_maksatbek Oct 25 '18 at 22:05
  • Old processors often had just one register used for operating on data. This register was traditionally called the *accumulator* because old calculators used it to sum up numbers you typed in. You can think of the 8086 CPU having 7 accumulators (`ax`, `bx`, `cx`, `dx`, `si`, `di`, and `bp`). Because the 8086 is based on the 8080 which has only one accumulator, the `ax` register is called *accumulator register* because that's what is was on the 8080. – fuz Oct 25 '18 at 22:07
  • @fuz I understood)) thank you so much for help – aizhan_maksatbek Oct 25 '18 at 22:08
  • @fuz - 8080 has a DAD (double add) instruction, where HL is effectively the accumulator. – rcgldr Oct 26 '18 at 00:11
  • 1
    BTW, *"eax, ax, al registers"* = it's the same one register, not three registers. Those different aliases just indicate the bit-size the instruction will target/affect (not 100% true/precise in 64b mode, where 32b `eax` target will automatically clear upper 32b, i.e. the instruction like `mov eax,2` will affect whole `rax`). So code: `mov eax,0x11223344` `mov ax,0x5566` `mov al,0xBB` will produce `eax = 0x112255BB` (composed by three different instructions). – Ped7g Oct 26 '18 at 05:55

2 Answers2

6

On older ancestors of 8086, many instructions were only available with the accumulator as an implicit destination. See https://en.wikipedia.org/wiki/Accumulator_(computing).

The name "accumulator" for 8086's AL/AX register is mostly historical, and related to 8086's design to make asm source translation from 8080 code possible mechanically. (Why are first four x86 GPRs named in such unintuitive order? and also The start of x86: Intel 8080 vs Intel 8086?)

There are special short-form encodings of many instructions using AL/AX/EAX (like add al, 2 is 2 bytes, but add cl, 2 is 3 bytes). 8086 (and later extensions in 186/386) made the registers more orthogonal than 8080 so you can add dx, cx without having to use the accumulator for all ALU instructions.

8086 has a (mostly) 2-operand instruction set, not an Accumulator Machine, in terms of instruction format. You can save code-size by using the accumulator register, but it's not required for most things especially with later extensions to the x86 ISA. Compare the x87 FPU instructions: everything has to use st0 as one of the operands. (In theoretical CS a Register Machine refers to the main memory as "registers", as opposed to a Turing machine with a tape. Real CPUs have registers separate from memory, unlike that idealized model. x86 instructions can have at most 1 explicit memory operand; the other(s) have to be registers. https://www.realworldtech.com/architecture-basics/2/ shows a taxonomy of real-world accumulator vs. register designs, with CISC x86 being load-store plus the ability for one or the other operand to be memory.)


On many older CPUs, you might have had to do the equivalent of mov ax,dx / add ax, cx. For example, 8080 / Z80 had instructions like LDA (load into accumulator) and ORA (OR into accumulator) where the accumulator destination was baked into the mnemonic and opcode. (This is where the inefficient and obsolete or ax,ax instead of test ax,ax idiom comes from.)

This 8080 opcode map http://pastraiser.com/cpu/i8080/i8080_opcodes.html show many instructions like SUB D and SUB C, where the implicit first operand is the accumulator, A.

But 8086 is a register machine, not an accumulator machine. There are several instructions that require using AX, such as mul / div, and cdq, but other than DIV and widening-multiply you can use whatever registers you want with movsx on 386 and later, and imul edx, edi.

Note that many 8-bit micros that only have ALU instructions using the accumulator aren't always pure accumulator machines as far as theory-of-computation. They typically have other registers they can use for addressing modes. But they are typically 1-operand instruction sets.

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
4

AX isn't any more or less temporary than the other registers.

Link to wiki article:

https://en.wikipedia.org/wiki/Accumulator_(computing)

8080 to 8086 register mapping and legacy name

A       AL   accumulator
H,L     BX   high, low memory pointer
B,C     CX   byte counter (also a memory pointer)
D,E     DX   data         (also a memory pointer)
SP      SP   stack pointer
...     SI   source index
...     DI   destination index
...     BP   base pointer (uses SS as default segment)
rcgldr
  • 23,179
  • 3
  • 24
  • 50