Why are Index Registers needed

cpuregister

In a cpu, why are/were Index Registers needed? You can of course live without them, but why would you want them? Wikipedia says that they are used for vector/array operations, but I'm not really sure what that means. (I am deciding on the architecture of my home-brew cpu)

Best Answer

variable = array[index];

(where index is a variable who's value is unknown at compile time) is a common thing to do in C. You can do something similar in x86 assembly:

mov edx, [ebx + 4 * eax]

Here, eax holds the value of the index variable, and we call eax an index register in this instruction. If ebx holds the address of array, and array is of a type which has a size of 4 bytes, then eax = n will store array[n] into edx.

Without index variables, this would be cumbersome to do.

Related Topic