In computer programming and architecture, an index register is an area of memory usually built into the central processing unit (CPU) to be used as a very fast counter to cycle through memory addresses or to keep track of loop-like operations. Depending on the type of system architecture, an index register can be a defined, dedicated register among other processor registers, or it can be any general-purpose register. Most commonly, an index register holds the current offset of a memory location, with another register containing the base address, so the combination of the two registers creates a complete memory address. One of the special functions of an index register, when one is specially designated by a CPU, is that it can be used to easily loop through memory addresses by incrementing or decrementing as needed so that data structures, such as arrays and stacks, can be traveled.
An index register is an area of low-level memory, usually on the CPU.
The index registers on a computer’s CPU are incredibly low-level memory areas that can usually only be accessed directly by a programmer through the use of assembly language or a similar low-level programming language. In some of the more common types of processors, two separate registers are defined as index registers, that is, the index source (SI) and index destination (DI) registers. Other processors do not specifically have index registers or supporting operators that require them, which means that any general-purpose register of the appropriate size can be used.
One of the most frequent uses of an index register is to act as a pointer to a memory location that contains a stream of data that needs to be accessed sequentially. An example can be seen when using an array of data where all elements are arranged consecutively in memory. If the index register is used to access an array, then it can contain the corresponding value of the offset of the element being accessed when added to another register that contains a base address, such as the data segment register. This can make it very easy to complete procedures such as copying the contents of a null-terminated string from a source location to a destination string.
Another use for an index register might be to store information about loops and other counters. Some system architectures prefer to use the index register to contain the number of iterations that have taken place in a loop, although other times any register can be used. Also, some assembly instructions specifically rely on source and destination index registers to perform certain operations, such as reading or writing block memory, as can be done to send information to a screen.