HOME

TheInfoList



OR:

Addressing modes are an aspect of the
instruction set architecture In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
in most
central processing unit A central processing unit (CPU), also called a central processor, main processor, or just processor, is the primary Processor (computing), processor in a given computer. Its electronic circuitry executes Instruction (computing), instructions ...
(CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how the
machine language In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
instructions in that architecture identify the
operand In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on. Unknown operands in equalities of expressions can be found by equation solving. Example The following arithmetic expres ...
(s) of each instruction. An addressing mode specifies how to calculate the effective
memory address In computing, a memory address is a reference to a specific memory location in memory used by both software and hardware. These addresses are fixed-length sequences of digits, typically displayed and handled as unsigned integers. This numeric ...
of an operand by using information held in
register Register or registration may refer to: Arts, entertainment, and media Music * Register (music), the relative "height" or range of a note, melody, part, instrument, etc. * ''Register'', a 2017 album by Travis Miller * Registration (organ), ...
s and/or constants contained within a machine instruction or elsewhere. In
computer programming Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, addressing modes are primarily of interest to those who write in
assembly language In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
s and to
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
writers. For a related concept see
orthogonal instruction set In computer engineering, an orthogonal instruction set is an instruction set architecture where all instruction types can use all addressing modes. It is "Orthogonality, orthogonal" in the sense that the instruction type and the addressing mode ma ...
which deals with the ability of any instruction to use any addressing mode.


Caveats

There are no generally accepted names for addressing modes: 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 A complex instruction set computer (CISC ) is a computer architecture in which single instructions can execute several low-level operations (such as a load from memory, an arithmetic operation, and a memory store) or are capable of multi-step ...
(CISC) architectures, such as the Digital Equipment Corporation (DEC) VAX, treat registers and literal or immediate constants as just another addressing mode. Others, such as the
IBM System/360 The IBM System/360 (S/360) is a family of mainframe computer systems announced by IBM on April 7, 1964, and delivered between 1965 and 1978. System/360 was the first family of computers designed to cover both commercial and scientific applicati ...
and its successors, and most
reduced instruction set computer In electronics and computer science, a reduced instruction set computer (RISC) is a computer architecture designed to simplify the individual instructions given to the computer to accomplish tasks. Compared to the instructions given to a com ...
(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 register or for a literal operand. Only the first interpretation applies to instructions such as "load effective address," which loads the address of the operand, not the operand itself. 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. Some computers, e.g.,
IBM 709 The IBM 709 is a computer system that was announced by IBM in January 1957 and first installed during August 1958. The 709 was an improved version of its predecessor, the IBM 704, and was the third of the IBM 700/7000 series of scientific compute ...
, RCA 3301, do not have a single address mode field but rather have separate fields for indirect addressing and indexing.


Number of addressing modes

Computer architectures vary greatly as to the number of addressing modes they provide in hardware. There are some benefits to eliminating complex addressing modes and using only one or a few simpler addressing modes, even though it requires a few extra instructions, and perhaps an extra register. It has proven much easier to design pipelined CPUs if the only addressing modes available are simple ones. Most RISC architectures have only about five simple addressing modes, while CISC architectures such as the DEC VAX have over a dozen addressing modes, some of which are quite complicated. The
IBM System/360 architecture The IBM System/360 architecture is the model independent architecture for the entire S/360 line of mainframe computers, including but not limited to the instruction set architecture. The elements of the architecture are documented in the ''IB ...
has only four addressing modes; a few more have been added for the
ESA/390 IBM Enterprise Systems Architecture is an instruction set architecture introduced by IBM as Enterprise Systems Architecture/370 (ESA/370) in 1988. It is based on the IBM System/370-XA architecture. It extended the dual-address-space mechanis ...
architecture. When there are only a few addressing modes, the particular addressing mode required is usually encoded within the instruction code (e.g. IBM System/360 and successors, most RISC). But when there are many 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 bits of each operand specifier to indicate the addressing mode for that particular operand. Keeping the addressing mode specifier bits separate from the opcode operation bits produces an
orthogonal instruction set In computer engineering, an orthogonal instruction set is an instruction set architecture where all instruction types can use all addressing modes. It is "Orthogonality, orthogonal" in the sense that the instruction type and the addressing mode ma ...
. 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.


Important use case

Some instruction set architectures, such as
Intel x86 x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. The ...
, IBM/360 and its successors, have a load effective address instruction. This calculates the effective operand address and loads it into a register, without accessing the memory it refers to. This can be useful when passing the address of an array element to a subroutine. It may also be a clever way of doing more calculations than normal in one instruction; for example, using such an instruction with the addressing mode "base+index+offset" (detailed below) allows one to add two registers and a constant together in one instruction and store the result in a third register.


Simple addressing modes for code

Some simple addressing modes for code are shown below. The nomenclature may vary depending on platform.


Absolute or direct

+----+------------------------------+ , 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-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. Max Maxfield
"Building a 4-Bit Computer: Assembly Language and Assembler"
Section "Addressing modes". 2019.
This is particularly useful in connection with jump instructions, 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 (roughly ±128 or ±512 bytes). For jumps to instructions that are not nearby, other addressing modes are used. Another advantage of PC-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.


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, as well as the CISC
IBM System/360 The IBM System/360 (S/360) is a family of mainframe computer systems announced by IBM on April 7, 1964, and delivered between 1965 and 1978. System/360 was the first family of computers designed to cover both commercial and scientific applicati ...
and successors, have subroutine call instructions that place the
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 (and sometimes authorized intermediaries) with a means to determine how to respond to the sender of the message ...
in an address register—the register indirect addressing mode is used to return from that subroutine call.


Sequential addressing modes for code


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 or instructions may refer to: A specific direction or order given to someone to perform a task or carry out a procedure. They provide clear guidance on how to achieve a desired outcome. They can be written or verbal, and they typically ...
and more complex
pipeline A pipeline is a system of Pipe (fluid conveyance), pipes for long-distance transportation of a liquid or gas, typically to a market area for consumption. The latest data from 2014 gives a total of slightly less than of pipeline in 120 countries ...
ing,
out-of-order execution In computer engineering, out-of-order execution (or more formally dynamic execution) is an instruction scheduling paradigm used in high-performance central processing units to make use of instruction cycles that would otherwise be wasted. In t ...
, 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 In compiler construction, a basic block is a straight-line code sequence with no branches in except to the entry and no branches out except at the exit. This restricted form makes a basic block highly amenable to analysis. Compilers usually decom ...
" of such sequential instructions exhibits both temporal and spatial
locality of reference In computer science, locality of reference, also known as the principle of locality, is the tendency of a processor to access the same set of memory locations repetitively over a short period of time. There are two basic types of reference localit ...
.


CPUs that do not use sequential execution

CPUs that do not use sequential execution with a program counter are extremely rare. In some CPUs, each instruction always specifies the address of next instruction. Such CPUs have an instruction pointer that holds that specified address; it is not a program counter because there is no provision for incrementing it. Such CPUs include some
drum memory Drum memory was a magnetic data storage device invented by Gustav Tauschek in 1932 in Austria. Drums were widely used in the 1950s and into the 1960s as computer memory. Many early computers, called drum computers or drum machines, used drum ...
computers such as the
IBM 650 The IBM 650 Magnetic Drum Data-Processing Machine is an early digital computer produced by IBM in the mid-1950s. It was the first mass-produced computer in the world. Almost 2,000 systems were produced, the last in 1962, and it was the firs ...
, the SECD machine, Librascope RPC 4000, and the RTX 32P. On processors implemented with horizontal microcode, the microinstruction may contain the high order bits of the next instruction address. Other computing architectures go much further, attempting to bypass the
von Neumann bottleneck The von Neumann architecture—also known as the von Neumann model or Princeton architecture—is a computer architecture based on the '' First Draft of a Report on the EDVAC'', written by John von Neumann in 1945, describing designs discus ...
using a variety of alternatives to the program counter.


Conditional execution

Some computer architectures have conditional instructions (such as ARM, but no longer for all instructions in 64-bit mode) or conditional load instructions (such as x86) which can in some cases make conditional branches unnecessary and avoid flushing the
instruction pipeline In computer engineering, instruction pipelining is a technique for implementing instruction-level parallelism within a single processor. Pipelining attempts to keep every part of the processor busy with some instruction by dividing incoming Mac ...
. An instruction such as a 'compare' is used to set a condition code, and subsequent instructions include a test on that condition code to see whether they are obeyed or ignored.


Skip

+------+-----+-----+ , skipEQ, reg1, reg2, skip the next 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 fixed offsets. 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 A status register, flag register, or condition code register (CCR) is a collection of status Flag (computing), flag bits for a Central processing unit, processor. Examples of such registers include FLAGS register (computing), FLAGS register in the ...
. 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 In computer engineering, instruction pipelining is a technique for implementing instruction-level parallelism within a single processor. Pipelining attempts to keep every part of the processor busy with some instruction by dividing incoming Mac ...
, though it may need to cause the next instruction to be ignored.


Simple addressing modes for data

Some simple addressing modes for data are shown below. The nomenclature may vary depending on platform.


Register (or, register direct)

+------+-----+-----+-----+ , 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

This is sometimes referred to as 'base plus displacement' or 'truncated'. +------+-----+-----+----------------+ , load , reg , base, offset , reg := RAM ase + offset +------+-----+-----+----------------+ (Effective address = offset + contents of specified base register) 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. The offset is often small in relation to the size of current computer memories. However, the principle of
locality of reference In computer science, locality of reference, also known as the principle of locality, is the tendency of a processor to access the same set of memory locations repetitively over a short period of time. There are two basic types of reference localit ...
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, for which one base register (the
frame pointer In computer science, a call stack is a stack data structure that stores information about the active subroutines and inline blocks of a computer program. This type of stack is also known as an execution stack, program stack, control stack, run- ...
) usually 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 (a record or structure), the offset can be usually used to select a field from that record.


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 showed that 98% of all the constants in a program would fit in 13 bits (see RISC design philosophy).


Implicit

+-----------------+ , clear carry bit , +-----------------+ +-------------------+ , clear Accumulator , +-------------------+ The implied addressing mode, also called the implicit addressing mode (
x86 assembly language x86 assembly language is a family of Low-level programming language, low-level programming languages that are used to produce object code for the x86 class of processors. These languages provide backward compatibility with CPUs dating back to th ...
), 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 < a := b + c; > can be done using the sequence < load b; add c; store a; > -- 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 A processor register is a quickly accessible location available to a computer's processor. Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-onl ...
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. Among the x86 instructions, some use implicit registers for one of the operands or results (multiplication, division, counting conditional jump). Some instruction sets (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. Some other instruction sets (such as
m68k The Motorola 68000 series (also known as 680x0, m68000, m68k, or 68k) is a family of 32-bit complex instruction set computer (CISC) microprocessors. During the 1980s and early 1990s, they were popular in personal computers and workstations and w ...
, ARM, and PowerPC) have more than one register that 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 instruction sets (e.g.
z/Architecture z/Architecture, initially and briefly called ESA Modal Extensions (ESAME), is IBM's 64-bit complex instruction set computer (CISC) instruction set architecture, implemented by its mainframe computers. IBM introduced its first z/Architecture ...
and
IA-32 IA-32 (short for "Intel Architecture, 32-bit", commonly called ''i386'') is the 32-bit version of the x86 instruction set architecture, designed by Intel and first implemented in the i386, 80386 microprocessor in 1985. IA-32 is the first incarn ...
/
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
) contain some instructions with implicit operands in order to maintain backwards compatibility with earlier designs. On some instruction sets, 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 The Popek and Goldberg virtualization requirements are a set of conditions sufficient for a computer architecture to support system virtualization efficiently. They were introduced by Gerald J. Popek and Robert P. Goldberg in their 1974 article " ...
—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. Some instruction sets have been designed where every operand is always implicitly specified in every instruction -- zero-operand 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 x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. Th ...
. Some RISC machines have a special ''Load Upper Literal'' instruction which places a 16- or 20-bit constant in the top half of a register. That can then be used as the base register in a base-plus-offset addressing mode which supplies the low-order 16 or 12 bits. The combination allows a full 32-bit address.


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. 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 In computer programming, a static variable is a variable that has been allocated "statically", meaning that its lifetime (or "extent") is the entire run of the program. This is in contrast to shorter-lived automatic variables, whose storage is ...
. 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. The start of the array is stored in the literal address (perhaps modified at program-load time by a relocating loader) 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 An index register in a computer's central processing unit, CPU is a processor register (or an assigned memory location) used for pointing to operand addresses during the run of a program. It is useful for stepping through String (computer science ...
to allow for the size of each array element. 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.


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 data structure, and the index could contain the offset of the one 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 A power of two is a number of the form where is an integer, that is, the result of exponentiation with number 2, two as the Base (exponentiation), base and integer  as the exponent. In the fast-growing hierarchy, is exactly equal to f_1^ ...
, so that shifting rather than multiplication can be used.


Register indirect

+------+------+-----+ , load , reg1 , 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 In medicine, a side effect is an effect of the use of a medicinal drug or other treatment, usually adverse but sometimes beneficial, that is unintended. Herbal and traditional medicines also have side effects. A drug or procedure usually used ...
(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 three computer architectures that have had implementation problems with regard to recovery from faults when this addressing mode is used: * DEC
PDP-11 The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
. Could have one or two autoincrement register operands. Some models, such as the PDP-11/45 and PDP-11/70, had a register that recorded modifications to registers, allowing the fault handler to undo the register modifications and re-execute the instruction. *
Motorola 68000 series The Motorola 68000 series (also known as 680x0, m68000, m68k, or 68k) is a family of 32-bit computing, 32-bit complex instruction set computer (CISC) microprocessors. During the 1980s and early 1990s, they were popular in personal computers and ...
. Could have one or two autoincrement register operands. The 68010 and later processors resolved the problem by saving the processor's internal state on
bus A bus (contracted from omnibus, with variants multibus, motorbus, autobus, etc.) is a motor vehicle that carries significantly more passengers than an average car or van, but fewer than the average rail transport. It is most commonly used ...
or address errors and restoring it when returning from the fault. *DEC VAX. Could have up to 6 autoincrement register operands. The First Part Done bit in the saved processor status longword in a stack frame for a fault is set if the faulting instruction must not be restarted at the beginning, resolving the problem.


Register autodecrement 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 or deferred

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 A word is a basic element of language that carries semantics, meaning, can be used on its own, and is uninterruptible. Despite the fact that language speakers often have an intuitive grasp of what a word is, there is no consensus among linguist ...
) which contains the actual effective address. On some machines the indirect word could indicate indexing, indirection, tallying or some combination. Indirect addressing may be used for code or data. It can make implementation of ''pointers'', ''references'', or ''
handle A handle is a part of, or an attachment to, an object that allows it to be grasped and object manipulation, manipulated by hand. The design of each type of handle involves substantial ergonomics, ergonomic issues, even where these are dealt wi ...
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 The PDP-8 is a family of 12-bit minicomputers that was produced by Digital Equipment Corporation (DEC). It was the first commercially successful minicomputer, with over 50,000 units sold during the model's lifetime. Its basic design follows the pi ...
,
Data General Nova The Nova is a series of 16-bit computing, 16-bit minicomputers released by the American company Data General. The Nova family was very popular in the 1970s and ultimately sold tens of thousands of units. The first model, known simply as "Nov ...
) had only a few registers and only a limited direct addressing range (8 bits). Hence the use of memory indirect addressing was almost the only way of referring to any significant amount of memory. Half of the DEC PDP-11's eight addressing modes are deferred. Register deferred @Rn is the same as register indirect as defined above. Predecrement deferred @-(Rn), postincrement deferred @(Rn)+, and indexed deferred @nn(Rn) modes point to addresses in memory which are read to find the address of the parameter. The PDP-11's deferred mode, when combined with the program counter, provide its absolute addressing mode.


PC-relative

+------+------+---------+----------------+ , load , reg1 , base=PC , offset , +------+------+---------+----------------+ reg1 := RAM C + offset (Effective address = PC + offset) The PC-relative addressing mode can be used to load a register with a value 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 references. Such CPUs include: The
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
architecture and the 64-bit
ARMv8-A ARM (stylised in lowercase as arm, formerly an acronym for Advanced RISC Machines and originally Acorn RISC Machine) is a family of RISC instruction set architectures (ISAs) for computer processors. Arm Holdings develops the ISAs and lice ...
architecture have PC-relative addressing modes, called "RIP-relative" in x86-64 and "literal" in ARMv8-A. The
Motorola 6809 The Motorola 6809 ("''sixty-eight-oh-nine''") is an 8-bit microprocessor with some 16-bit features. It was designed by Motorola's Terry Ritter and Joel Boney and introduced in 1978. Although source compatible with the earlier Motorola 6800, the ...
also supports a PC-relative addressing mode. The
PDP-11 The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
architecture, the VAX architecture, and the 32-bit
ARM architecture ARM (stylised in lowercase as arm, formerly an acronym for Advanced RISC Machines and originally Acorn RISC Machine) is a family of reduced instruction set computer, RISC instruction set architectures (ISAs) for central processing unit, com ...
s support PC-relative addressing by having the PC in the register file. The
IBM International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American Multinational corporation, multinational technology company headquartered in Armonk, New York, and present in over 175 countries. It is ...
z/Architecture z/Architecture, initially and briefly called ESA Modal Extensions (ESAME), is IBM's 64-bit complex instruction set computer (CISC) instruction set architecture, implemented by its mainframe computers. IBM introduced its first z/Architecture ...
includes specific instructions, e.g., Load Relative Long, with PC-relative addressing if the General-Instructions-Extension Facility is active. When this addressing mode is used, the compiler typically places the constants in a literal pool immediately before or immediately after the subroutine that uses them, to prevent accidentally executing those constants as instructions. This addressing mode, which always fetches data from memory or stores data to memory 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 fetch data from or store data to memory, 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 period, 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-minus-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. This flag is referred to as an indirection bit, and the resulting pointer is a tagged pointer, the indirection bit tagging whether it is a direct pointer or an indirect pointer. Care is needed to ensure that a chain of indirect addresses does not refer to itself; if it does, one can get an
infinite loop In computer programming, an infinite loop (or endless loop) is a sequence of instructions that, as written, will continue endlessly, unless an external intervention occurs, such as turning off power via a switch or pulling a plug. It may be inte ...
while trying to resolve an address. The
IBM 1620 The IBM 1620 was a model of scientific minicomputer produced by IBM. It was announced on October 21, 1959, and was then marketed as an inexpensive scientific computer. After a total production of about two thousand machines, it was withdrawn on N ...
, the
Data General Nova The Nova is a series of 16-bit computing, 16-bit minicomputers released by the American company Data General. The Nova family was very popular in the 1970s and ultimately sold tens of thousands of units. The first model, known simply as "Nov ...
, and the
HP 2100 The HP 2100 is a series of 16-bit minicomputers that were produced by Hewlett-Packard (HP) from the mid-1960s to early 1990s. Tens of thousands of machines in the series were sold over its 25-year lifetime, making HP the fourth-largest minicomp ...
series each have such a multi-level memory indirect, and could enter such an infinite address calculation loop. The memory indirect addressing mode on the Nova influenced the invention of indirect threaded code. The DEC
PDP-10 Digital Equipment Corporation (DEC)'s PDP-10, later marketed as the DECsystem-10, is a mainframe computer family manufactured beginning in 1966 and discontinued in 1983. 1970s models and beyond were marketed under the DECsystem-10 name, especi ...
computer with 18-bit addresses and
36-bit 36-bit computers were popular in the early mainframe computer era from the 1950s through the early 1970s. Starting in the 1960s, but especially the 1970s, the introduction of 7-bit ASCII and 8-bit EBCDIC led to the move to machines using 8-bit ...
words allowed multi-level indirect addressing with the possibility of using an index register at each stage as well. The priority interrupt system was queried before decoding of every address word. So, an indirect address loop would not prevent execution of device service routines, including any
preemptive multitasking In computing, preemption is the act performed by an external scheduler — without assistance or cooperation from the task — of temporarily interrupting an executing task, with the intention of resuming it at a later time. This preemptive sc ...
scheduler's time-slice expiration handler. A looping instruction would be treated like any other compute-bound job.


Memory-mapped registers

On some computers, there were addresses that referred to registers rather than to primary storage, or to primary memory used to implement those registers. Although on some early computers there were register addresses at the high end of the address range, e.g.,
IBM 650 The IBM 650 Magnetic Drum Data-Processing Machine is an early digital computer produced by IBM in the mid-1950s. It was the first mass-produced computer in the world. Almost 2,000 systems were produced, the last in 1962, and it was the firs ...
, IBM 7070, the trend has been to use only register address at the low end and to use only the first 8 or 16 words of memory (e.g.
ICL 1900 ICT 1900 was a family of mainframe computers released by International Computers and Tabulators (ICT) and later International Computers Limited (ICL) during the 1960s and 1970s. The 1900 series was notable for being one of the few non-American ...
, DEC PDP-6/PDP-10). This meant that there was no need for a separate "add register to register" instruction – one 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, if the "fast registers" option, which provided faster circuits to store the registers but still allowed them to be addressed as if they were in memory, was installed, a tight inner loop loaded into the first few words of memory ran much faster than it would have in magnetic core memory. Later models of the DEC
PDP-11 The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
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 and autoincrement

The DEC
PDP-8 The PDP-8 is a family of 12-bit minicomputers that was produced by Digital Equipment Corporation (DEC). It was the first commercially successful minicomputer, with over 50,000 units sold during the model's lifetime. Its basic design follows the pi ...
minicomputer had eight special locations (at addresses 8 through 15). When accessed via memory indirect addressing, these locations would automatically increment prior to use. This made it easy to step through memory in a loop without needing to use the accumulator to increment the address. The
Data General Nova The Nova is a series of 16-bit computing, 16-bit minicomputers released by the American company Data General. The Nova family was very popular in the 1970s and ultimately sold tens of thousands of units. The first model, known simply as "Nov ...
minicomputer had 16 special memory locations at addresses 16 through 31. When accessed via memory indirect addressing, 16 through 23 would automatically increment before use, and 24 through 31 would automatically decrement before use.


Zero page

The
Data General Nova The Nova is a series of 16-bit computing, 16-bit minicomputers released by the American company Data General. The Nova family was very popular in the 1970s and ultimately sold tens of thousands of units. The first model, known simply as "Nov ...
,
Motorola 6800 The 6800 ("''sixty-eight hundred''") is an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System (later dubbed ''68xx'') that also included serial and parall ...
family, and
MOS Technology 6502 The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") William Mensch and the moderator both pronounce the 6502 microprocessor as ''"sixty-five-oh-two"''. is an 8-bit computing, 8-bit microprocessor that was desi ...
family of processors had very few internal registers. Arithmetic and logical instructions were mostly performed against values in memory as opposed to internal registers. As a result, many instructions required a two-byte (16-bit) location to memory. Given that opcodes on these processors were only one byte (8 bits) 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 similarly 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, which limited its use since free space was limited.


Direct page

The zero page address mode was enhanced in several late model 8-bit processors, including the WDC 65816, the CSG 65CE02, and the
Motorola 6809 The Motorola 6809 ("''sixty-eight-oh-nine''") is an 8-bit microprocessor with some 16-bit features. It was designed by Motorola's Terry Ritter and Joel Boney and introduced in 1978. Although source compatible with the earlier Motorola 6800, the ...
. 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 64 KB of memory. The CSG 65CE02 allowed the direct page to be moved to any 256-byte boundary within the first 64 KB of memory by storing an 8-bit offset value in the new base page (B) register. The Motorola 6809 could do the same with its direct page (DP) register. The WDC 65816 went a step further and allowed the direct page to be moved to any location within the first 64 KB of memory by storing a 16-bit offset value in the new direct (D) 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 checks that the index value is 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.


Indirect to bit field within word

Some computers had special indirect addressing modes for subfields within words. The GE/Honeywell 600 series character addressing indirect word specified either 6-bit or 9-bit character fields within its
36-bit 36-bit computers were popular in the early mainframe computer era from the 1950s through the early 1970s. Starting in the 1960s, but especially the 1970s, the introduction of 7-bit ASCII and 8-bit EBCDIC led to the move to machines using 8-bit ...
word. The DEC
PDP-10 Digital Equipment Corporation (DEC)'s PDP-10, later marketed as the DECsystem-10, is a mainframe computer family manufactured beginning in 1966 and discontinued in 1983. 1970s models and beyond were marketed under the DECsystem-10 name, especi ...
, also 36-bit, had special instructions which allowed memory to be treated as a sequence of fixed-size bit fields or bytes of any size from 1 bit to 36 bits. A one-word sequence descriptor in memory, called a "byte pointer", 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 one bit per word unused. Implementations of C had to use four 9-bit bytes per word, since the 'malloc' function in C assumes that the size of an ''int'' is some multiple of the size of a ''char''; the actual multiple is determined by the system-dependent compile-time operator
sizeof sizeof is a unary operator in the C and C++ programming languages that evaluates to the storage size of an expression or a data type, measured in units sized as char. Consequently, the expression sizeof(char) evaluates to 1. The number of b ...
.


Index next instruction

The Elliott 503,Dave Brooks
"Some Old Computers"
the Elliott 803,Bill Purvis
"Some details of the Elliott 803B hardware"
/ref> and the
Apollo Guidance Computer The Apollo Guidance Computer (AGC) was a digital computer produced for the Apollo program that was installed on board each Apollo command module (CM) and Apollo Lunar Module (LM). The AGC provided computation and electronic interfaces for guidanc ...
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 indexed jump. Note that the instruction is modified on-the-fly and remains unchanged in memory, i.e. it is not
self-modifying code In computer science, self-modifying code (SMC or SMoC) is source code, code that alters its own instruction (computer science), instructions while it is execution (computing), executing – usually to reduce the instruction path length and imp ...
. If the value being added to the next instruction was large enough, it could modify the opcode of that instruction as well as or instead of the address.


Glossary


See also

*
Instruction set architecture In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
*
Address bus In computer architecture, a bus (historically also called a data highway or databus) is a communication system that transfers data between components inside a computer or between computers. It encompasses both hardware (e.g., wires, optical ...


Notes


References


External links


Addressing modes in assembly language


{{CPU technologies Computer architecture Machine code Assembly languages