Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Addressing mode
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Aspect of the instruction set architecture of CPUs}} {{about|addressing fields in instructions|IBM addressing bits in the [[Program status word|PSW]]|IBM System/370-XA#31-bit virtual addressing|and|z/Architecture#Addressing modes}} {{More citations needed|date=May 2009}} '''Addressing modes''' are an aspect of the [[instruction set architecture]] in most [[central processing unit]] (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how the [[machine code|machine language]] [[instruction (computer science)|instructions]] in that architecture identify the [[operand]](s) of each instruction. An addressing mode specifies how to calculate the effective [[memory address]] of an operand by using information held in [[processor register|register]]s and/or constants contained within a machine instruction or elsewhere. In [[computer programming]], addressing modes are primarily of interest to those who write in [[assembly language]]s and to [[compiler]] writers. For a related concept see [[orthogonal instruction set]] which deals with the ability of any instruction to use any addressing mode. ==Caveats== {{Unreferenced section|date=May 2012}} 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]] (CISC) architectures, such as the [[Digital Equipment Corporation|Digital Equipment Corporation (DEC)]] [[VAX]], treat registers and [[value (computer science)|literal or immediate constants]] as just another addressing mode. Others, such as the [[IBM System/360]] and its successors, 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 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]], RCA 3301,<ref>{{cite manual | title = System Reference Manual - RCA 3301 REALCOM EDP | id = 94-16-000-1 | date = September 1967 | url = http://bitsavers.org/pdf/rca/3301/94-16-000_RCA_3301_System_Reference_Manual_Sep67.pdf | publisher = [[RCA]] | access-date = December 21, 2023 }} </ref> 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.<ref>{{cite journal|url=http://portal.acm.org/citation.cfm?doid=36204.36193|title=How many addressing modes are enough?|author1=F. Chow|author2=S. Correll|author3=M. Himelstein|author4=E. Killian|author5=L. Weber|journal=ACM SIGARCH Computer Architecture News|year=1987|volume=15|issue=5|pages=117–121|doi=10.1145/36177.36193|url-access=subscription}}</ref><ref>{{cite web|url=http://i.stanford.edu/pub/cstr/reports/csl/tr/86/300/CSL-TR-86-300.pdf|title=An Overview of the MIPS-X-MP Project|author1=John L. Hennessy|author-link1=John L. Hennessy|author2=Mark A. Horowitz|author-link2=Mark Alan Horowitz|year=1986|quote=... MIPS-X uses a single addressing mode: base register plus offset. This simple addressing mode allows the computation of the effective address to begin very early ...}}</ref> It has proven<ref>{{cite web|url=http://www.csee.umbc.edu/~squire/cs411_l19.html|title=Lecture 19, Pipelining Data Forwarding|work=CS411 Selected Lecture Notes|author=Dr. Jon Squire}}</ref><ref>{{cite web|url=http://hpc.serc.iisc.ernet.in/~govind/hpc/L10-Pipeline.txt |title=High Performance Computing, Notes of Class 11 (Sept. 15 and 20, 2000) - Pipelining |access-date=2014-02-08 |url-status=dead |archive-url=https://web.archive.org/web/20131227033204/http://hpc.serc.iisc.ernet.in/~govind/hpc/L10-Pipeline.txt |archive-date=2013-12-27 }}</ref><ref name=Guardian>{{cite book |url=https://books.google.com/books?id=Nibfj2aXwLYC&q=deep%20pipeline%20processor&pg=PA94 |title=Modern Processor Design |author=John Paul Shen, Mikko H. Lipasti |year=2004 |publisher=[[McGraw-Hill Professional]]|isbn=9780070570641 }}</ref> much easier to design [[instruction pipeline|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]] has only four addressing modes; a few more have been added for the [[ESA/390]] 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 [[bit]]s 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]]. Even on a computer with many addressing modes, measurements of actual programs<ref name="hennessy-patterson-c54x">{{cite book|url=https://books.google.com/books?id=XX69oNsazH4C&pg=PA104|title=Computer Architecture: A Quantitative Approach|author1=John L. Hennessy|author2=David A. Patterson|author-link2=David Patterson (computer scientist)|page=104|quote=The C54x has 17 data addressing modes, not counting register access, but the four found in MIPS account for 70% of the modes. Autoincrement and autodecrement, found in some RISC architectures, account for another 25% of the usage. This data was collected form a measurement of static instructions for the C-callable library of 54 DSP routines coded in assembly language.|isbn=9780080502526|date=2002-05-29|publisher=Elsevier }}</ref> 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.<ref>{{cite web|url=http://users.encs.concordia.ca/~tahar/coen6741/notes/Chapter2-4p.pdf|title=Instruction Set Principles: Addressing Mode Usage (Summary)|author=Dr. Sofiène Tahar|quote=3 programs measured on machine with all address modes (VAX) ... 75% displacement and immediate|archive-url=https://web.archive.org/web/20110930125040/http://users.encs.concordia.ca/~tahar/coen6741/notes/Chapter2-4p.pdf|archive-date=2011-09-30 }}</ref><ref name="hennessy-patterson-c54x"/><ref>{{cite book|chapter=Efficient and Language-Independent Mobile Programs|author1=Ali-Reza Adl-Tabatabai|author2=Geoff Langdale|author3=Steven Lucco|author4=Robert Wahbe|title=Proceedings of the ACM SIGPLAN 1996 conference on Programming language design and implementation - PLDI '96|year=1995|pages=127–136|doi=10.1145/231379.231402|isbn=0897917952|s2cid=2534344|quote=79% of all instructions executed could be replaced by RISC instructions or synthesized into RISC instructions using only basic block instruction combination.|chapter-url=http://dl.acm.org/citation.cfm?id=231402}}</ref> ==Important use case== Some instruction set architectures, such as [[x86|Intel x86]], IBM/360 and its successors, have a '''load effective address''' instruction.<ref>{{ cite manual | publisher = [[IBM]] | title = z/Architecture - Principles of Operation | id = SA22-7832-13 | date = May 2022 | edition = Fourteenth | section = Load Address | section-url = https://www.vm.ibm.com/library/other/22783213.pdf#page=773 | page = 7-269 | url = https://www.vm.ibm.com/library/other/22783213.pdf | access-date = May 30, 2025 }}</ref> 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.<ref>{{ cite manual | publisher = IBM | title = IBM System/360 Principles of Operation | section = Instruction Use Examples | section-url = http://bitsavers.org/pdf/ibm/360/princOps/A22-6821-7_360PrincOpsDec67.pdf#page=139 | url = http://bitsavers.org/pdf/ibm/360/princOps/A22-6821-7_360PrincOpsDec67.pdf | page = [http://bitsavers.org/pdf/ibm/360/princOps/A22-6821-7_360PrincOpsDec67.pdf#page=147 135] | id = A22-6821-7 | date = September 1968 | access-date = 12 July 2019 }}</ref> ==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 [[program counter|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.<ref name="maxfield" > Max Maxfield. [https://www.eeweb.com/building-a-4-bit-computer-assembly-language-and-assembler-part-1/ "Building a 4-Bit Computer: Assembly Language and Assembler"]. Section "Addressing modes". 2019. </ref> This is particularly useful in connection with [[Branch (computer science)|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).<ref>{{cite web|last1=Kong|first1=Shing|last2=Patterson|first2=David|author-link2=David Patterson (computer scientist)|title=Instruction set design|year=1995|at=Slide 27|url=http://www.cs.berkeley.edu/~pattrsn/152/lec3.ps}}</ref> 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 code|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]] and successors, have subroutine call instructions that place the [[return statement|return address]] 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]] and more complex [[pipeline (computing)|pipeline]]ing, [[out-of-order execution]], 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]]" of such sequential instructions exhibits both temporal and spatial [[locality of reference]]. ====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]] computers such as the [[IBM 650]], the [[SECD machine]], [[LGP-30#RPC 4000|Librascope RPC 4000]], and the RTX 32P.<ref>{{cite web|url = http://www.ece.cmu.edu/~koopman/stack_computers/sec5_3.html |title =Architecture of the RTX 32P|work = Stack Computers|first = Philip|last= Koopman|date= 1989}}</ref> On processors implemented with [[Microcode#Horizontal microcode|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 architecture#Von Neumann bottleneck|von Neumann bottleneck]] using a variety of [[program counter#Consequences in machine architecture|alternatives to the program counter]]. ===Conditional execution=== Some computer architectures have conditional instructions (such as [[ARM architecture|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]]. An instruction such as a 'compare' is used to set a [[status register|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.{{efn|Most often just NSI+1 on word-oriented machines, but, e.g., the Compare Accumulator and Skip (CAS) on the [[IBM 7090]] can skip to NSI+1 or NSI+2.}} 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]]. 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]], 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. ==={{anchor|REGISTER PLUS REGISTER}}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. ==={{anchor|REGISTER PLUS IMMIEDIATE CONSTANT}}Base plus offset, and variations=== This is sometimes referred to as 'base plus displacement' or 'truncated'. +------+-----+-----+----------------+ | load | reg | base| offset | reg := RAM[base + 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]] 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]]) 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, <code>move.l #$FEEDABBA, D0</code> 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 S. Tanenbaum|Andrew Tanenbaum]] showed that 98% of all the constants in a program would fit in 13 bits (see [[Reduced instruction set computer#Instruction set philosophy|RISC design philosophy]]). ===Implicit=== +-----------------+ | clear carry bit | +-----------------+ +-------------------+ | clear Accumulator | +-------------------+ The implied addressing mode, also called the implicit addressing mode ([[x86 assembly language]]), 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 machine]]s 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]] 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 [[Motorola 68000 family|m68k]], 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]] and [[IA-32]]/[[x86-64]]) 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]]—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 -- [[Instruction set#Number of operands|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]]. 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 [[stride of an array|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]]. 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 [[field (computer science)|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]] to allow for the [[stride of an array|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 [[stride of an array|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]], so that [[bit shift|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 effect (computer science)|side effects]] (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: *[[Digital Equipment Corporation|DEC]] [[PDP-11]]. Could have one or two autoincrement register operands.<ref>{{cite book |url=http://www.bitsavers.org/pdf/dec/pdp11/handbooks/EB-23657-18_PDP-11_Architecture_Handbook_1983.pdf |title=PDP-11 Architecture Handbook |publisher=[[Digital Equipment Corporation]] |date=1973}}</ref> 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.<ref>{{cite book |url=http://www.bitsavers.org/pdf/dec/pdp11/handbooks/PDP-1145_Handbook_1973.pdf |title=PDP-11/45 Processor Handbook |pages=150–153 |publisher=[[Digital Equipment Corporation]] |date=1973}}</ref> *[[Motorola 68000 series]]. Could have one or two autoincrement register operands.<ref>{{cite book |url=http://bitsavers.org/components/motorola/68000/M68000PM_AD_Rev_1_Programmers_Reference_Manual_1992.pdf |title=M68000 Family Programmer's Reference Manual |publisher=[[Motorola]] |date=1992}}</ref> The [[68010]] and later processors resolved the problem by saving the processor's internal state on [[bus error|bus]] or address errors and restoring it when returning from the fault.<ref>{{cite book |url=http://bitsavers.org/components/motorola/68000/MC68010_68012_Data_Sheet_May85.pdf |title=MC68010/MC68012 16-/32-Bit Virtual Memory Microprocessors |pages=5{{hyp}}12-5{{hyp}}15 |publisher=[[Motorola]] |date=May 1985}}</ref><ref>{{cite book |url=http://bitsavers.org/components/motorola/68000/MC68020_32-Bit_Microprocessor_Users_Manual_1984.pdf |title=MC68020 32-Bit Microprocessor User's Manual |pages=6{{hyp}}9-6{{hyp}}10 |publisher=[[Prentice-Hall]] |date=1984 |isbn=0-13-541418-0}}</ref><ref>{{cite book |url=http://bitsavers.org/components/motorola/68000/MC68030_Users_Manual_3ed_1990.pdf |title=MC68030 Enhanced 32-Bit Microprocessor User's Manual |edition=Third |pages=8{{hyp}}7-8{{hyp}}8 |publisher=[[Prentice-Hall]] |date=1990 |isbn=0-13-566423-3}}</ref><ref>{{cite book |url=http://bitsavers.org/components/motorola/68000/MC68040_Users_Manual_1989.pdf |title=MC68040 32-Bit Microprocessor User's Manual |edition=Third |pages=9{{hyp}}8-9{{hyp}}9 |publisher=[[Motorola]] |date=1989}}</ref> *DEC [[VAX]]. Could have up to 6 autoincrement register operands. The First Part Done bit in the saved [[status register|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.<ref>{{cite book |url=http://www.bitsavers.org/pdf/dec/vax/archSpec/EY-3459E-DP_VAX_Architecture_Reference_Manual_1987.pdf |title=VAX Architecture Reference Manual |page=21 |publisher=[[Digital Equipment Corporation]] |date=1987 |isbn=0-932376-86-X}}</ref> ===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 [[#Register autoincrement indirect|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 (data type)|word]]) which contains the actual effective address. On some machines the indirect word could indicate indexing, indirection, tallying{{efn|Either increment or decrement.}} or some combination. Indirect addressing may be used for code or data. It can make implementation of ''pointers'', ''references'', or ''[[handle (computing)|handle]]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]], [[Data General Nova]]) 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 [[PDP-11 architecture|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[PC + 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]] architecture and the 64-bit [[ARMv8-A]] architecture<ref>{{cite web|url=https://quequero.org/2014/04/introduction-to-arm-architecture/|title=Introduction to ARMv8 64-bit Architecture|date = 9 April 2014|work = UIC Academy |publisher = quequero.org}}</ref> have PC-relative addressing modes, called "RIP-relative" in x86-64 and "literal" in ARMv8-A. The [[Motorola 6809]] also supports a PC-relative addressing mode. The [[PDP-11]] architecture, the [[VAX]] architecture, and the 32-bit [[ARM architecture]]s support PC-relative addressing by having the PC in the register file. The [[IBM]] [[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.<ref>{{cite book|url=http://bitsavers.org/pdf/ibm/704/24-6661-2_704_Manual_1955.pdf|title=704 Electronic Data-Processing Machine Manual of Operation|pages=10–11|publisher=[[IBM]]|year=1955}}</ref><ref>{{cite book|url=http://bitsavers.org/pdf/ibm/7090/22-6528-4_7090Manual.pdf|title=Reference Manual IBM 7090 Data Processing System|pages=9–10|publisher=IBM|year=1962}}</ref> ==={{anchor|multilevel memory indirect}}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]] while trying to resolve an address. The [[IBM 1620]], the [[Data General Nova]], and the [[HP 2100]] 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 [[threaded code#Development|indirect threaded code]]. The DEC [[PDP-10]] computer with [[18-bit computing|18-bit]] addresses and [[36-bit computing|36-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.<ref>{{cite book |title=DEC-10-HMAA-D: PDP-10 KA10 Central Processor Maintenance Manual |date=December 1968 |publisher=[[Digital Equipment Corporation]] |location=[[Maynard, Massachusetts]] |pages=2–11 |edition=1st Printing |url=http://bitsavers.org/pdf/dec/pdp10/KA10/DEC-10-HMAA_D_KA10_Maint_Dec68.pdf#page=23 |access-date=15 May 2021 |format=PDF |quote=Figure 2-9: Effective Address Calculation: test "PI RQ ?"}}</ref> So, an indirect address loop would not prevent execution of device service routines, including any [[Preemption (computing)#Preemptive multitasking|preemptive multitasking]] 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]],<ref>{{cite manual | title = 650 magnetic drum data-processing machine - manual of operation | id = 22-6060-2 | date = June 1955 | page = [http://www.bitsavers.org/pdf/ibm/650/22-6060-2_650_OperMan.pdf#page=8 9] | section = Storage | section-url = http://www.bitsavers.org/pdf/ibm/650/22-6060-2_650_OperMan.pdf#page=7 | url = http://www.bitsavers.org/pdf/ibm/650/22-6060-2_650_OperMan.pdf | accessdate = March 14, 2022 }} </ref>{{efn|Condensor storage units for 650: :8000 Console switches :8001 Distributor :8002 Lower accumulator :8003 Upper accumulator }} [[IBM 7070]],<ref>{{cite manual | title = Reference Manual - IBM 7070 Data Processing System | id = A22-7003-0 | date = January 1960 | page = 252 | section = Core Storage and Register Addresses | section-url = http://www.bitsavers.org/pdf/ibm/7070/A22-7003-01_7070_Reference_Jan60.pdf#page=253 | url = http://www.bitsavers.org/pdf/ibm/7070/A22-7003-01_7070_Reference_Jan60.pdf | accessdate = March 14, 2022 }} </ref>{{efn|For 5K or 10K 7070 :00xx Index register xx :9991 Accumulator 1 :9992 Accumulator 2 :9993 Accumulator 3 :9995 Program register{{efn|Only valid from console|name=console}} :9999 Instruction counter{{efn|name=console}} }} 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. [[ICT 1900 series|ICL 1900]], 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]] 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]] minicomputer had eight special locations (at addresses 8 through 15). When accessed via memory indirect addressing, these locations would automatically increment prior to use.<ref>{{ Citation | last1 = Jones | first1 = Douglas | title = Reference Instructions on the PDP-8 | url = http://homepage.cs.uiowa.edu/~jones/pdp8/man/mri.html#autoindex | access-date = 1 July 2013 }}</ref> 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]] minicomputer had 16 special memory locations at addresses 16 through 31.<ref>{{ Citation | last1 = Friend | first1 = Carl | title = Data General NOVA Instruction Set Summary | url = http://users.rcn.com/crfriend/museum/doco/DG/Nova/ | access-date = 1 July 2013 }}</ref> 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]], [[Motorola 6800]] family, and [[MOS Technology 6502]] 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 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-600 series|GE/Honeywell 600 series]] character addressing indirect word specified either 6-bit or 9-bit character fields within its [[36-bit computing|36-bit]] word. The DEC [[PDP-10]], 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 (programming language)|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'';<ref>[http://www.codingunit.com/c-reference-stdlib-h-function-malloc "C Reference: function malloc()"]</ref> the actual multiple is determined by the system-dependent compile-time operator [[sizeof]]. ===Index next instruction=== The [[Elliott 503]],<ref name="brooks">Dave Brooks. [https://web.archive.org/web/20141101211113/http://members.iinet.com.au/~daveb/history.html#puzzle "Some Old Computers"].</ref> the [[Elliott 803]],<ref name="brooks"/><ref>Bill Purvis. [https://web.archive.org/web/20080616173228/http://bil.members.beeb.net/inst803.html "Some details of the Elliott 803B hardware"]</ref> and the [[Apollo Guidance Computer]] 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 <code>JUMP 0</code> into a <code>JUMP 20</code>, 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]]. 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== {{glossary}} {{term|Indirect}}{{defn|Data referred to through a [[pointer (computing)|pointer]] or [[memory address|address]].}} {{term|Immediate}}{{defn|Data embedded directly in an [[Instruction (computing)|instruction]] or command list.}} {{term|Index}}{{defn|A dynamic offset, typically held in an [[index register]], possibly scaled by an object size.}} {{term|Offset}}{{defn|An immediate value added to an address; e.g., corresponding to structure field access in the [[C programming language]].}} {{term|Relative}}{{defn|An address formed relative to another address.}} {{term|Post increment}}{{defn|The stepping of an address past data used, similar to <code>*p++</code> in the [[C programming language]], used for [[stack pop]] operations.}} {{term|Pre decrement}}{{defn|The decrementing of an address prior to use, similar to <code>*--p</code> in the [[C programming language]], used for [[stack push]] operations.}} {{glossary end}} ==See also== *[[Instruction set architecture]] *[[Address bus]] ==Notes== {{notelist}} ==References== {{reflist|2}} ==External links== * [http://www.osdata.com/topic/language/asm/address.htm Addressing modes in assembly language] * [http://www.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/addressMode.html Addressing modes] {{CPU technologies}} [[Category:Computer architecture]] [[Category:Machine code]] [[Category:Assembly languages]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Anchor
(
edit
)
Template:CPU technologies
(
edit
)
Template:Citation
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite manual
(
edit
)
Template:Cite web
(
edit
)
Template:Defn
(
edit
)
Template:Efn
(
edit
)
Template:Glossary
(
edit
)
Template:Glossary end
(
edit
)
Template:More citations needed
(
edit
)
Template:Notelist
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Term
(
edit
)
Template:Unreferenced section
(
edit
)