assemblyx86x86-64cpu-architecturecpu-registers

Why the number of x86 int registers is 8?


Recently I started to learn x86 assembly language and CPU architecture. I noticed that total number of int registers is 8, but for x86-64 it is 16.

Why? There must be some explanation.


Solution

  • The x86 architecture has evolved from its earliest incarnation as an 8008 back in the early 1970s. At the time, memory bytes and therefore opcode space was extremely precious; only 3 bits were set aside for the (at the time) A, B, C, D, E, F, (and IIRC) H and L registers, all 8 bits. (I remember how painfully hard those machines were to program, and how slow! You had to load H and L with a memory address, before a memory read or write!)

    Since then, Intel has evolved the instruction set, through 8080, 8086, 80186, 80286, 80386, 80486 architectures of the late 1980s, extending the registers to 16 and 32 bits, but staying with the same 3 bits to select a register.

    It wasn't until AMD designed a 64 bit version of the 80486 architure, that a 4th register bit was added by virtue of adding (since now memory and therefore opcode bytes are cheap) an instruction prefix byte. This prefix byte in essence adds "8" to the register number selected by those same 3 legacy register bits; this means the "register number" is spread out across the instruction, which makes for an ugly decoder, but transistors are now cheap, too.

    The excuse for 16 registers is "register pressure". The ideal CPU will do all necessary arithmetic in its registers, always having enough so it doesn't have to sometimes spill (store and reload later) a register to memory to make space for another computation. Measurements (and experience) have shown that 8 registers was not really quite enough to avoid such spills, and since spills touch memory, they slow down the processor considerably. I think 32 is considered (carefully measured) to be more than enough registers, but that would have required 2 bits, and 16 is close enough to ideal to be very practical. And, AMD for awhile was able to use their 64 bit offering, and 16 registers rather than a mere 8, as effective high-tech marketing features.

    Intel, discovering they were losing the 64 bit processor war to AMD, tried to produce their own 64 bit extension of the x86, but Microsoft said they were supporting the AMD instruction set, and would not support 2 different x86 64 bit instruction sets. Intel folded, and now has essentially the same basic 64 bit instruction set that AMD offered.

    You'll find that extremely modern versions of these CPUs have vector registers sets of 16 and 32 (I think) registers; opcode bits are much cheaper now and instruction fetch rates are incredible.