All Topics  
Addressing mode

 

   Email Print
   Bookmark   Link






 

Addressing mode



 
 
Addressing modes are an aspect of the instruction set architecture in most central processing unit
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
 (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how machine language
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
 instructions
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
 in that architecture identify the operand
Operand

An operand is one of the inputs of an operator in mathematics. The following arithmetic expression shows an example of operators and operands:...
 (or operands) of each instruction. An addressing mode specifies how to calculate the effective memory address of an operand by using information held in register
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
s and/or constants contained within a machine instruction or elsewhere.

In computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
, addressing modes are primarily of interest to compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 writers and to those who write code directly in assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
.

that there is no generally accepted way of naming the various addressing modes.






Discussion
Ask a question about 'Addressing mode'
Start a new discussion about 'Addressing mode'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Addressing modes are an aspect of the instruction set architecture in most central processing unit
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
 (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how machine language
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
 instructions
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
 in that architecture identify the operand
Operand

An operand is one of the inputs of an operator in mathematics. The following arithmetic expression shows an example of operators and operands:...
 (or operands) of each instruction. An addressing mode specifies how to calculate the effective memory address of an operand by using information held in register
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
s and/or constants contained within a machine instruction or elsewhere.

In computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
, addressing modes are primarily of interest to compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 writers and to those who write code directly in assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
.

Caveats

Note that there is no generally accepted way of naming the various addressing modes. In particular, different authors and computer manufacturers may give different names to the same addressing mode, or the same names to different addressing modes. Furthermore, an addressing mode which, in one given architecture, is treated as a single addressing mode may represent functionality that, in another architecture, is covered by two or more addressing modes. For example, some complex instruction set computer
Complex instruction set computer

A complex instruction set computer is a computer instruction set architecture in which each instruction can execute several low-level operations, such as a load from Memory , an arithmetic operator, and a memory , all in a single instruction....
 (CISC) computer architectures, such as the Digital Equipment Corporation (DEC)
Digital Equipment Corporation

Digital Equipment Corporation was a pioneering United States company in the computer industry. It is often referred to within the computing industry as DEC ....
 VAX
VAX

VAX was an instruction set architecture developed by Digital Equipment Corporation in the mid-1970s. A 32-bit complex instruction set computer ISA, it was designed to extend or replace DEC's various Programmed Data Processor ISAs....
, treat registers and literal/immediate constants
Value (computer science)

In computer science, a value is a sequence of bits that is interpreted according to some data type. It is possible for the same sequence of bits to have different values, depending on the type used to interpret its meaning....
 as just another addressing mode. Others, such as the IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 System/390 and most reduced instruction set computer (RISC) designs, encode this information within the instruction. Thus, the latter machines have three distinct instruction codes for copying one register to another, copying a literal constant into a register, and copying the contents of a memory location into a register, while the VAX has only a single "MOV" instruction.

The term "addressing mode" is itself subject to different interpretations: either "memory address calculation mode" or "operand accessing mode". Under the first interpretation instructions that do not read from memory or write to memory (such as "add literal to register") are considered not to have an "addressing mode". The second interpretation allows for machines such as VAX which use operand mode bits to allow for a literal operand. Only the first interpretation applies to instructions such as "load effective address".

The addressing modes listed below are divided into code addressing and data addressing. Most computer architectures maintain this distinction, but there are, or have been, some architectures which allow (almost) all addressing modes to be used in any context.

The instructions shown below are purely representative in order to illustrate the addressing modes, and do not necessarily reflect the mnemonics used by any particular computer.

How many addressing modes?

Different computer architectures vary greatly as to the number of addressing modes they provide. At the cost of a few extra instructions, and perhaps an extra register, it is normally possible to use the simpler addressing modes instead of the more complicated modes. It has proven much easier to design pipelined
Instruction pipeline

File:5 Stage Pipeline.svgAn instruction pipeline is a technique used in the design of computers and other digital electronic devices to increase their instruction throughput ....
 CPUs if the only addressing modes available are simple ones.

Most RISC machines have only about five simple addressing modes, while CISC machines such as the DEC VAX supermini have over a dozen addressing modes, some of which are quite complicated. The IBM System/360
System/360

The IBM System/360 is a mainframe computer system family announced by IBM on April 7, 1964. It was the first family of computers making a clear distinction between computer architecture and implementation, allowing IBM to release a suite of compatible designs at different price points....
 mainframe had only three addressing modes; a few more have been added for the System/390.

When there are only a few addressing modes, the particular addressing mode required is usually encoded within the instruction code (e.g. IBM System/390, most RISC). But when there are lots of addressing modes, a specific field is often set aside in the instruction to specify the addressing mode. The DEC VAX allowed multiple memory operands for almost all instructions, and so reserved the first few bit
Bit

A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory....
s of each operand specifier to indicate the addressing mode for that particular operand.

Even on a computer with many addressing modes, measurements of actual programs indicate that the simple addressing modes listed below account for some 90% or more of all addressing modes used. Since most such measurements are based on code generated from high-level languages by compilers, this reflects to some extent the limitations of the compilers being used.

Useful side effect

Some processors, such as Intel x86 and the IBM/390, have a Load effective address instruction. This performs a calculation of the effective operand address, but instead of acting on that memory location, it loads the address that would have been accessed into a register. This can be useful when passing the address of an array element to a subroutine. It may also be a slightly sneaky way of doing more calculation than normal in one instruction; for example, using such an instruction with the addressing mode "base+index+offset" allows one to add two registers and a constant together in one instruction.

Simple addressing modes for code


Absolute


+----+------------------------------+ |jump| address | +----+------------------------------+ (Effective PC address = address)

The effective address for an absolute instruction address is the address parameter itself with no modifications.

PC-relative


+----+------------------------------+ |jump| offset | jump relative +----+------------------------------+ (Effective PC address = next instruction address + offset, offset may be negative)

The effective address for a PC
Program counter

The program counter, or PC is a processor register that indicates where the computer is in its instruction sequence. Depending on the details of the particular computer, the PC holds either the address of the instruction being executed, or the address of the next instruction to be executed....
-relative instruction address is the offset parameter added to the address of the next instruction. This offset is usually signed to allow reference to code both before and after the instruction.

This is particularly useful in connection with jumps, because typical jumps are to nearby instructions (in a high-level language most if or while statements are reasonably short). Measurements of actual programs suggest that an 8 or 10 bit offset is large enough for some 90% of conditional jumps .

Another advantage of program-relative addressing is that the code may be position-independent, i.e. it can be loaded anywhere in memory without the need to adjust any addresses.

Some versions of this addressing mode may be conditional referring to two registers ("jump if reg1

reg2"), one register ("jump unless reg1

0") or no registers, implicitly referring to some previously-set bit in the status register
Status register

A status register is a collection of Flag bits for a Central processing unit. A popular example of a status register is the FLAGS register of x86 architecture based microprocessors....
. See also conditional execution below.

Register indirect


+-------+-----+ |jumpVia| reg | +-------+-----+ (Effective PC address = contents of register 'reg')

The effective address for a Register indirect instruction is the address in the specified register. For example, (A7) to access the content of address register A7.

The effect is to transfer control to the instruction whose address is in the specified register.

Many RISC machines have a subroutine call instruction that places the return address
Return address

In postal mail, a return address is an explicit inclusion of the address of the person sending the message. It provides the recipient with a means to determine how to respond to the sender of the message if needed....
 in an address register -- the register indirect addressing mode is used to return from that subroutine call.

Sequential addressing modes


sequential execution


+------+ | nop | execute the following instruction +------+ (Effective PC address = next instruction address)

The CPU, after executing a sequential instruction, immediately executes the following instruction.

Sequential execution is not considered to be an addressing mode on some computers.

Most instructions on most CPU architectures are sequential instructions. Because most instructions are sequential instructions, CPU designers often add features that deliberately sacrifice performance on the other instructions -- branch instructions -- in order to make these sequential instructions run faster.

Conditional branches load the PC with one of 2 possible results, depending on the condition -- most CPU architectures use some other addressing mode for the "taken" branch, and sequential execution for the "not taken" branch.

Many features in modern CPUs -- instruction prefetch
Instruction prefetch

In computer architecture, instruction prefetch is a technique used in microprocessors to speed up the execution of a program by reducing wait states....
 and more complex pipelineing, Out-of-order execution
Out-of-order execution

In computer engineering, out-of-order execution, OoOE, is a paradigm used in most high-performance microprocessors to make use of Instruction cycle that would otherwise be wasted by a certain type of costly delay....
, etc. -- maintain the illusion that each instruction finishes before the next one begins, giving the same final results, even though that's not exactly what happens internally.

Each "basic block
Basic block

In computing, a basic block is code that has one entry point , one exit point and no jump instructions contained within it. The start of a basic block may be jumped to from more than one location....
" of such sequential instructions exhibits both temporal and spatial locality of reference
Locality of reference

In computer science, locality of reference, also known as the principle of locality, is the phenomenon of the same value or related computer storage locations being frequently accessed....
.

CPUs that do not use sequential execution are extremely rare -- they include some drum memory
Drum memory

Drum memory is a magnetic data storage device and was an early form of computer memory widely used in the 1950s and into the 1960s, invented by Gustav Tauschek in 1932 in Austria....
 computers and the RTX 32P
Microcode

Microcode is a layer of lowest-level instructions involved in the implementation of machine code instructions in many computers and other processors; it resides in a special high-speed memory and translates machine instructions into sequences of detailed circuit-level operations....
, which has no program counter.

Conditional execution


Some computer architectures (e.g. ARM
ARM architecture

The ARM architecture is a 32-bit RISC central processing unit architecture developed by ARM Limited that is widely used in embedded system designs....
) have conditional instructions which can in some cases obviate the need for conditional branches and avoid flushing the instruction pipeline
Instruction pipeline

File:5 Stage Pipeline.svgAn instruction pipeline is a technique used in the design of computers and other digital electronic devices to increase their instruction throughput ....
. An instruction such as a 'compare' is used to set a condition code
Status register

A status register is a collection of Flag bits for a Central processing unit. A popular example of a status register is the FLAGS register of x86 architecture based microprocessors....
, and subsequent instructions include a test on that condition code to see whether they are obeyed or ignored.

skip


+------+-----+-----+ |skipEQ| reg1| reg2| skip the following instruction if reg1=reg2 +------+-----+-----+ (Effective PC address = next instruction address + 1)

Skip addressing may be considered a special kind of PC-relative addressing mode with a fixed "+1" offset. Like PC-relative addressing, some CPUs have versions of this addressing mode that only refer to one register ("skip if reg1

0") or no registers, implicitly referring to some previously-set bit in the status register
Status register

A status register is a collection of Flag bits for a Central processing unit. A popular example of a status register is the FLAGS register of x86 architecture based microprocessors....
. Other CPUs have a version that selects a specific bit in a specific byte to test ("skip if bit 7 of reg12 is 0").

Unlike all other conditional branches, a "skip" instruction never needs to flush the instruction pipeline
Instruction pipeline

File:5 Stage Pipeline.svgAn instruction pipeline is a technique used in the design of computers and other digital electronic devices to increase their instruction throughput ....
.

Simple addressing modes for data


Register


+------+-----+-----+-----+ | mul | reg1| reg2| reg3| reg1 := reg2 * reg3; +------+-----+-----+-----+

This "addressing mode" does not have an effective address and is not considered to be an addressing mode on some computers.

In this example, all the operands are in registers, and the result is placed in a register.

Base plus offset, and variations


+------+-----+-----+----------------+ | load | reg | base| offset | reg := RAM[base + offset] +------+-----+-----+----------------+ (Effective address = offset + contents of specified base register)

The offset is usually a signed 16-bit value (though the 80386 expanded it to 32 bits).

If the offset is zero, this becomes an example of register indirect addressing; the effective address is just the value in the base register.

On many RISC machines, register 0 is fixed at the value zero. If register 0 is used as the base register, this becomes an example of absolute addressing. However, only a small portion of memory can be accessed (64 kilobyte
Kilobyte

Kilobyte is a unit of Computer data storage equal to either 1,024 bytes or 1,000 bytes , depending on context.It is abbreviated in a number of ways: KB, kB, K and Kbyte....
s, if the offset is 16 bits).

The 16-bit offset may seem very small in relation to the size of current computer memories (which is why the 80386 expanded it to 32-bit). It could be worse: IBM System/360 mainframes only have an unsigned 12-bit offset. However, the principle of locality of reference
Locality of reference

In computer science, locality of reference, also known as the principle of locality, is the phenomenon of the same value or related computer storage locations being frequently accessed....
 applies: over a short time span, most of the data items a program wants to access are fairly close to each other.

This addressing mode is closely related to the indexed absolute addressing mode.

Example 1: Within a subroutine a programmer will mainly be interested in the parameters and the local variables, which will rarely exceed 64 KB
Kilobyte

Kilobyte is a unit of Computer data storage equal to either 1,024 bytes or 1,000 bytes , depending on context.It is abbreviated in a number of ways: KB, kB, K and Kbyte....
, for which one base register (the frame pointer) suffices. If this routine is a class method in an object-oriented language, then a second base register is needed which points at the attributes for the current object (this or self in some high level languages).

Example 2: If the base register contains the address of a composite type
Composite type

In computer science, composite types are datatypes which can be constructed in a programming language out of that language's basic primitive types and other composite types....
 (a record or structure), the offset can be used to select a field from that record (most records/structures are less than 32 kB in size).

Immediate/literal


+------+-----+-----+----------------+ | add | reg1| reg2| constant | reg1 := reg2 + constant; +------+-----+-----+----------------+

This "addressing mode" does not have an effective address, and is not considered to be an addressing mode on some computers.

The constant might be signed or unsigned. For example move.l #$FEEDABBA, D0 to move the immediate hex value of "FEEDABBA" into register D0.

Instead of using an operand from memory, the value of the operand is held within the instruction itself. On the DEC VAX machine, the literal operand sizes could be 6, 8, 16, or 32 bits long.

Andrew Tanenbaum
Andrew S. Tanenbaum

Andrew Stuart "Andy" Tanenbaum is a professor of computer science at the Vrije Universiteit, Amsterdam in the Netherlands. He is best known as the author of MINIX, a free Unix-like operating system for teaching purposes, and for his computer science textbooks, regarded as standard texts in the field....
 showed that 98% of all the constants in a program would fit in 13 bits (see RISC design philosophy
Reduced instruction set computer

The acronym RISC , for reduced instruction set computing, represents a CPU design strategy emphasizing the insight that simplified instructions that "do less" may still provide for higher performance if this simplicity can be utilized to make instructions execute very quickly....
).

Implicit


+-----------------+ | clear carry bit | +-----------------+

The implied addressing mode, also called the implicit addressing mode, does not explicitly specify an effective address for either the source or the destination (or sometimes both).

Either the source (if any) or destination effective address (or sometimes both) is implied by the opcode.

Implied addressing was quite common on older computers (up to mid-1970s). Such computers typically had only a single register in which arithmetic could be performed -- the accumulator. Such accumulator machines implicitly reference that accumulator in almost every instruction. For example, the operation can be done using the sequence -- the destination (the accumulator) is implied in every "load" and "add" instruction; the source (the accumulator) is implied in every "store" instruction.

Later computers generally had more than one general purpose register or RAM location which could be the source or destination or both for arithmetic -- and so later computers need some other addressing mode to specify the source and destination of arithmetic.

Many computers (such as x86 and AVR) have one special-purpose register called the stack pointer which is implicitly incremented or decremented when pushing or popping data from the stack, and the source or destination effective address is (implicitly) the address stored in that stack pointer.

Most 32-bit computers (such as ARM and PowerPC) have more than one register which could be used as a stack pointer -- and so use the "register autoincrement indirect" addressing mode to specify which of those registers should be used when pushing or popping data from a stack.

Some current computer architectures (e.g. IBM/390 and Intel Pentium) contain some instructions with implicit operands in order to maintain backwards compatibility with earlier designs.

On many computers, instructions that flip the user/system mode bit, the interrupt-enable bit, etc. implicitly specify the special register that holds those bits. This simplifies the hardware necessary to trap those instructions in order to meet the
Popek and Goldberg virtualization requirements
Popek and Goldberg virtualization requirements

The Popek and Goldberg virtualization requirements are a set of sufficient conditions for a computer architecture to efficiently support system virtualization....
 -- on such a system, the trap logic does not need to look at any operand (or at the final effective address), but only at the opcode.

A few CPUs have been designed where every operand is always implicitly specified in every instruction -- zero-operand
Instruction set

An instruction set is a list of all the instruction , and all their variations, that a processor can execute.Instructions include:* Arithmetic such as add and subtract...
 CPUs.

Other addressing modes for code or data


Absolute/Direct


+------+-----+--------------------------------------+ | load | reg | address | +------+-----+--------------------------------------+ (Effective address = address as given in instruction)

This requires space in an instruction for quite a large address. It is often available on CISC machines which have variable-length instructions, such as x86.

Some RISC machines have a special Load Upper Literal instruction which places a 16-bit constant in the top half of a register. An OR literal instruction can be used to insert a 16-bit constant in the lower half of that register, so that a full 32-bit address can then be used via the register-indirect addressing mode, which itself is provided as "base-plus-offset" with an offset of 0.

Indexed absolute


+------+-----+-----+--------------------------------+ | load | reg |index| address| +------+-----+-----+--------------------------------+ (Effective address = address + contents of specified index register)

This also requires space in an instruction for quite a large address. The address could be the start of an array or vector, and the index could select the particular array element required. The processor may scale the index register to allow for the size of each array element
Stride of an array

In computer programming, the stride of an array refers to the number of locations in Random Access Memory between successive array elements, measured in bytes or in units of the size of the array's elements....
.

Note that this is more or less the same as base-plus-offset addressing mode, except that the offset in this case is large enough to address any memory location.

Example 1: Within a subroutine, a programmer may define a string as a local constant or a static variable
Static variable

In computer programming, the data value of a static variable persists for the life of the running process. Typically, a static variable has a broader Scope than other variables....
. The address of the string is stored in the literal address in the instruction. The offset -- which character of the string to use on this iteration of a loop -- is stored in the index register.

Example 2: A programmer may define several large arrays as globals or as class variables
Field (computer science)

In computer science, data that has several parts can be divided into fields. For example, a computer may represent today's date as three distinct fields: the day, the month and the year....
. The start of the array is stored in the literal address (perhaps modified at program-load time by a relocating loader
Loader (computing)

In computing, a loader is the part of an operating system that is responsible for loading programs from executables into memory, preparing them for execution and then executing them....
) of the instruction that references it. The offset -- which item from the array to use on this iteration of a loop -- is stored in the index register. Often the instructions in a loop re-use the same register for the loop counter and the offsets of several arrays.

Base plus index


+------+-----+-----+-----+ | load | reg | base|index| +------+-----+-----+-----+ (Effective address = contents of specified base register + contents of specified index register)

The base register could contain the start address of an array or vector, and the index could select the particular array element required. The processor may scale the index register
Index register

An index register in a computer's central processing unit is a processor register used for modifying operand addresses during the run of a program, typically for doing vector/array operations....
 to allow for the size of each array element
Stride of an array

In computer programming, the stride of an array refers to the number of locations in Random Access Memory between successive array elements, measured in bytes or in units of the size of the array's elements....
. This could be used for accessing elements of an array passed as a parameter.

Base plus index plus offset


+------+-----+-----+-----+----------------+ | load | reg | base|index| offset | +------+-----+-----+-----+----------------+ (Effective address = offset + contents of specified base register + contents of specified index register)

The base register could contain the start address of an array or vector of records, the index could select the particular record required, and the offset could select a field within that record. The processor may scale the index register to allow for the size of each array element
Stride of an array

In computer programming, the stride of an array refers to the number of locations in Random Access Memory between successive array elements, measured in bytes or in units of the size of the array's elements....
.

Scaled


+------+-----+-----+-----+ | load | reg | base|index| +------+-----+-----+-----+ (Effective address = contents of specified base register + scaled contents of specified index register)

The base register could contain the start address of an array or vector, and the index could contain the number of the particular array element required.

This addressing mode dynamically scales the value in the index register to allow for the size of each array element, e.g. if the array elements are double precision floating-point numbers occupying 8 bytes each then the value in the index register is multiplied by 8 before being used in the effective address calculation. The scale factor is normally restricted to being a power of two
Power of two

In mathematics, a power of two is any of the integer exponentiation of the number 2 ; in other words, two multiplication by itself a certain number of times....
, so that shifting rather than multiplication can be used.

Register indirect


+------+-----+-----+ | load | reg | base| +------+-----+-----+ (Effective address = contents of base register)

A few computers have this as a distinct addressing mode. Many computers just use base plus offset with an offset value of 0. For example, (A7)

Register autoincrement indirect


+------+-----+-------+ | load | reg | base | +------+-----+-------+ (Effective address = contents of base register)

After determining the effective address, the value in the base register is incremented by the size of the data item that is to be accessed. For example, (A7)+ would access the content of the address register A7, then increase the address pointer of A7 by 1 (usually 1 word). Within a loop, this addressing mode can be used to step through all the elements of an array or vector.

In high-level languages it is often thought to be a good idea that functions which return a result should not have side effects
Side effect (computer science)

In computer science, a subroutine or expression is said to produce a side effect if it modifies some state_ in addition to returning a value. For example, a function might modify a global or a static variable, modify one of its arguments, write data to a display or file, or read some data from other side-effecting functions....
 (lack of side effects makes program understanding and validation much easier). This addressing mode has a side effect in that the base register is altered. If the subsequent memory access causes an error (e.g. page fault, bus error, address error) leading to an interrupt, then restarting the instruction becomes much more problematic since one or more registers may need to be set back to the state they were in before the instruction originally started.

There have been at least two computer architectures which have had implementation problems with regard to recovery from interrupts when this addressing mode is used:
  • Motorola 68000(address is represented in 24 bits). Could have one or two autoincrement register operands. The 68010+ resolved the problem by saving the processor's internal state on bus
    Bus error

    In computing, a bus error is generally an attempt to access computer storage that the CPU cannot physically address. Bus errors can also be caused by any general device fault that the computer detects....
     or address errors.
  • DEC VAX. Could have up to 6 autoincrement register operands. Each operand access could cause two page fault
    Page fault

    In computer storage technology, a page is a fixed-length block of memory that is used as a unit of transfer between physical memory and external storage like a hard disk, and a page fault is an interrupt to the software raised by the hardware, when a program accesses a page that is mapped in address space, but not loaded in physical memory....
    s (if operands happened to straddle a page boundary). Of course the instruction itself could be over 50 bytes long and might straddle a page boundary as well!


Autodecrement register indirect


+------+-----+-----+ | load | reg | base| +------+-----+-----+ (Effective address = new contents of base register)

Before determining the effective address, the value in the base register is decremented by the size of the data item which is to be accessed.

Within a loop, this addressing mode can be used to step backwards through all the elements of an array or vector. A stack can be implemented by using this mode in conjunction with the previous addressing mode (autoincrement).

See the discussion of side-effects under the autoincrement addressing mode.

Memory indirect

Any of the addressing modes mentioned in this article could have an extra bit to indicate indirect addressing, i.e. the address calculated using some mode is in fact the address of a location (typically a complete word) which contains the actual effective address.

Indirect addressing may be used for code or data. It can make implementation of pointers or references or handle
Handle (computing)

A handle is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a database or an operating system....
s
much easier, and can also make it easier to call subroutines which are not otherwise addressable. Indirect addressing does carry a performance penalty due to the extra memory access involved.

Some early minicomputers (e.g. DEC PDP-8
PDP-8

The PDP-8 was the first successful commercial minicomputer, produced by Digital Equipment Corporation in the 1960s. DEC introduced it on 22 March 1965, and sold more than 50,000 systems, the most of any computer up to that date....
, Data General Nova
Data General Nova

The Data General Nova was a popular 16-bit minicomputer built by the United States company Data General starting in 1969. The Nova was packaged into a single rack mount case and had enough power to do most simple computing tasks....
) had only a few registers and only a limited addressing range (8 bits). Hence the use of memory indirect addressing was almost the only way of referring to any significant amount of memory.

PC-relative


+------+------+---------+----------------+ | load | reg1 | base=PC | offset | reg1 := RAM[PC + offset] +------+------+---------+----------------+ (Effective address = PC + offset)

The PC-relative addressing mode is used to load a register from a "constant" stored in program memory a short distance away from the current instruction. It can be seen as a special case of the "base plus offset" addressing mode, one that selects the program counter (PC) as the "base register".

There are a few CPUs that support PC-relative data loads. Such CPUs include:

The x86-64
X86-64

x86-64 is a superset of the x86. x86-64 Central processing units can run existing 32-bit or 16-bit x86 programs at full speed, but also support new programs written with a 64-bit address space and other additional capabilities....
 architecture supports "RIP-relative" addressing, which uses the 64-bit instruction pointer
Program counter

The program counter, or PC is a processor register that indicates where the computer is in its instruction sequence. Depending on the details of the particular computer, the PC holds either the address of the instruction being executed, or the address of the next instruction to be executed....
 RIP as a base register. This encourages position-independent code
Position-independent code

In computing, position-independent code or position-independent executable is machine instruction code that executes properly regardless of where in computer storage it resides....
.

The ARM architecture
ARM architecture

The ARM architecture is a 32-bit RISC central processing unit architecture developed by ARM Limited that is widely used in embedded system designs....
 supports PC-relative addressing.

When this addressing mode is used, the compiler typically places the constants in a literal pool
Literal pool

In computer science, and specifically in compiler and assembly language#Assembler design, a literal pool is a lookup table used to hold literals during assembly and execution ....
 immediately before or immediately after the subroutine that uses them, to prevent accidentally executing those constants as instructions.

This addressing mode, which always modifies a data register and then sequentially falls through to execute the next instruction (the effective address points to data), should not be confused with "PC-relative branch" which does not modify any data register, but instead branches to some other instruction at the given offset (the effective address points to an executable instruction).

Obsolete addressing modes

The addressing modes listed here were used in the 1950–1980 time frame, but are no longer available on most current computers. This list is by no means complete; there have been many other interesting and peculiar addressing modes used from time to time, e.g. absolute-plus-logical-OR of two or three index registers.

Multi-level memory indirect

If the word size is larger than the address then the word referenced for memory-indirect addressing could itself have an indirect flag set to indicate another memory indirect cycle. Care is needed to ensure that a chain of indirect addresses does not refer to itself; if it did, you could get an infinite loop while trying to resolve an address.

The DEC PDP-10
PDP-10

The PDP-10 was a mainframe computer manufactured by Digital Equipment Corporation from the late 1960s on; the name stands for "Programmed Data Processor model 10"....
 computer with 18-bit addresses and 36-bit words allowed multi-level indirect addressing with the possibility of using an index register at each stage as well.

Memory-mapped registers

On some computers, the registers were regarded as occupying the first 8 or 16 words of memory (e.g. ICL 1900, DEC PDP-10). This meant that there was no need for a separate "Add register to register" instruction — you could just use the "add memory to register" instruction.

In the case of early models of the PDP-10, which did not have any cache memory, you could actually load a tight inner loop into the first few words of memory (the fast registers in fact), and have it run much faster than if it would have in magnetic core memory.

Later models of the DEC PDP-11
PDP-11

The PDP-11 was a series of 16-bit minicomputers sold by Digital Equipment Corporation from 1970 into the 1990s. Though not explicitly conceived as successor to DEC's PDP-8 computer in the Programmed Data Processor series of computers , the PDP-11 replaced the PDP-8 in many Real-time computing....
 series mapped the registers onto addresses in the input/output area, but this was primarily intended to allow remote diagnostics. Confusingly, the 16-bit registers were mapped onto consecutive 8-bit byte addresses.

Memory indirect, autoincrement

On some early minicomputers (e.g. DEC PDP-8
PDP-8

The PDP-8 was the first successful commercial minicomputer, produced by Digital Equipment Corporation in the 1960s. DEC introduced it on 22 March 1965, and sold more than 50,000 systems, the most of any computer up to that date....
, Data General Nova
Data General Nova

The Data General Nova was a popular 16-bit minicomputer built by the United States company Data General starting in 1969. The Nova was packaged into a single rack mount case and had enough power to do most simple computing tasks....
), there were typically 16 special memory locations. When accessed via memory indirect addressing, 8 would automatically increment after use and 8 would automatically decrement after use. This made it very easy to step through memory in loops without using any registers.

Zero page

The Motorola 6800
Motorola 6800

The 6800 is an 8-bit microprocessor produced by Motorola and released shortly after the Intel 8080 in late 1974. It had 78 instructions, including the famous, undocumented Halt and Catch Fire bus test instruction....
 family and MOS Technology 6502
MOS Technology 6502

The MOS Technology 6502 is an 8-bit microprocessor that was designed by Chuck Peddle and Bill Mensch for MOS Technology in 1975. When it was introduced, it was the least expensive full-featured central processing unit on the market by a considerable margin, costing less than one-sixth the price of competing designs from larger companies such...
 family of processors were a register poor series of CISC microprocessors. Arithmetic and logical instructions were mostly performed against values in memory as opposed to internal registers. As a result, instructions were generally required to include a two byte (16-bit) location to memory. Given that opcodes on these processors were only one byte (8-bit) in length, memory addresses could make up a significant part of code size.

Designers of these processors included a partial remedy known as "zero page" addressing. The initial 256 bytes of memory ($0000 - $00FF; a.k.a., page "0") could be accessed using a one byte absolute or indexed memory address. This reduced instruction execution time by one clock cycle and instruction length by one byte. By storing often used data in this region, programs could be made smaller and faster.

As a result, the zero page was used similar to a register file. On many systems, however, this resulted in high utilization of the zero page memory area by the operating system and user programs. This limited its use since free space was limited.

Direct page

The zero page address mode was enhanced in several descendants of the MOS Technology 6502, including the WDC 65816, the MOS Technology 65CE02
MOS Technology 65CE02

The 65CE02 is a CPU core developed by Commodore Semiconductor Group that has been used in the MOS Technology 4510 micro controller in the Commodore Commodore 65....
, and the Motorola 6809
Motorola 6809

The Motorola 6809 is an 8-bit microprocessor central processing unit from Motorola, introduced circa 1977-78. It was a major advance over both its predecessor, the Motorola 6800, and the related, MOS Technology 6502....
. The new mode, known as "direct page" addressing, added the ability to move the 256 byte zero page memory window from the start of memory (offset address $0000) to a new location within the first 64KB of memory.

The MOS 65CE02 allowed the direct page to be moved to any 256 byte boundary within the first 64KB of memory by storing an 8-bit offset value in the new B (block) register, equivalent to the 8-bit 6809 DP (direct page) register. The WDC 65816 went a step further and allowed the direct page to be moved to any location within the first 64KB of memory by storing a 16-bit offset value in the new D (direct) register.

As a result, a greater number of programs were able to utilize the enhanced direct page addressing mode versus legacy processors that only included the zero page addressing mode.

Scaled index with bounds checking

This is similar to scaled index addressing, except that the instruction has two extra operands (typically constants), and the hardware would check that the index value was between these bounds.

Another variation uses vector descriptors to hold the bounds; this makes it easy to implement dynamically allocated arrays and still have full bounds checking.

Register indirect to byte within word

The DEC PDP-10
PDP-10

The PDP-10 was a mainframe computer manufactured by Digital Equipment Corporation from the late 1960s on; the name stands for "Programmed Data Processor model 10"....
 computer used 36-bit words. It had a special addressing mode which allowed memory to be treated as a sequence of bytes (bytes could be any size from 1 bit to 36 bits). A one-word sequence descriptor held the current word address within the sequence, a bit position within a word, and the size of each byte.

Instructions existed to load and store bytes via this descriptor, and to increment the descriptor to point at the next byte (bytes were not split across word boundaries). Much DEC software used five 7-bit bytes per word (plain ASCII characters), with 1 bit unused per word. Implementations of C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 had to use four 9-bit bytes per word, since C assumes that you can access every bit of memory by accessing consecutive bytes

Index next instruction

The Elliott 503, the Elliott 803
Elliott 803

The Elliott 803 was a small computer manufactured by the United Kingdom company Elliott Brothers in the 1960s. About 250 were built and most British universities and colleges bought one....
, and the Apollo Guidance Computer
Apollo Guidance Computer

The Apollo Guidance Computer was the first recognizably modern embedded system, used in Real-time computing by astronaut pilot to collect and provide flight information, and to automatically control all of the navigational functions of the Apollo spacecraft....
 only used absolute addressing, and did not have any index registers. Thus, indirect jumps, or jumps through registers, were not supported in the instruction set. Instead, it could be instructed to add the contents of the current memory word to the next instruction. Adding a small value to the next instruction to be executed could, for example, change a JUMP 0 into a JUMP 20, thus creating the effect of an indirect jump via self-modifying code
Self-modifying code

In computer science, self-modifying code is Code that alters its own Instruction while it is Execution - usually to reduce the instruction path length and improve performance....
.

External links