In computer architecture and programming, an index register is an area of memory that is usually built into the central processing unit (CPU) to be used as a very fast counter for traversing memory addresses or keeping track of loop-like operations. Depending on the type of system architecture, an index register can be a dedicated register defined among other processor registers, or it can be any general purpose register. Most commonly, one index register contains 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 specially designated by a CPU, is that it can be used to easily traverse memory addresses incrementing or decrementing as needed so that data structures, such as arrays and stacks, can be traveled.
An index register is a low-level memory area, usually in the CPU.
Index registers in a computer’s CPU are incredibly low-level areas of memory that are generally only directly accessible 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 support operators that require them, which means that any general purpose register of the appropriate size can be used.
One of the most common uses of an index register is to act as a pointer to a memory location that contains a stream of data that must be accessed sequentially. An example can be seen when using a data array where all elements are arranged consecutively in memory. If the index register is used to access an array, 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 of an index register could be to store information about loops and other counters. Some system architectures prefer to use the index register to hold the number of iterations that have taken place in a cycle, 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, such as can be done to output information to a display.