You are on page 1of 4

Simple addressing modes for code

[edit] Absolute
+----+------------------------------+ |jump| address | +----+------------------------------+ (Effective PC address = address)

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

[edit] 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. This is particularly useful in connection with jumps, because typical jumps are to nearby instructions (in a high-level language most if or while statements are reasonably short). Measurements of actual programs suggest that an 8 or 10 bit offset is large enough for some 90% of conditional jumps[citation needed]. Another advantage of program-relative addressing is that the code may be positionindependent, i.e. it can be loaded anywhere in memory without the need to adjust any addresses. Some versions of this addressing mode may be conditional referring to two registers ("jump if reg1==reg2"), one register ("jump unless reg1==0") or no registers, implicitly referring to some previously-set bit in the status register. See also conditional execution below.

[edit] Register indirect


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

The effective address for a Register indirect instruction is the address in the specified register. For example, (A7) to access the content of address register A7. The effect is to transfer control to the instruction whose address is in the specified register. Many RISC machines have a subroutine call instruction that places the return address in an address registerthe register indirect addressing mode is used to return from that subroutine call.

[edit] Simple addressing modes for data


[edit] Register
+------+-----+-----+-----+ | mul | reg1| reg2| reg3| +------+-----+-----+-----+ reg1 := reg2 * reg3;

This "addressing mode" does not have an effective address and is not considered to be an addressing mode on some computers. In this example, all the operands are in registers, and the result is placed in a register.

[edit] Base plus offset, and variations


This is sometimes referred to as 'base plus displacement'
+------+-----+-----+----------------+ | load | reg | base| offset | +------+-----+-----+----------------+ reg := RAM[base + offset]

(Effective address = offset + contents of specified base register)

The offset is usually a signed 16-bit value (though the 80386 expanded it to 32 bits). If the offset is zero, this becomes an example of register indirect addressing; the effective address is just the value in the base register. On many RISC machines, register 0 is fixed at the value zero. If register 0 is used as the base register, this becomes an example of absolute addressing. However, only a small portion of memory can be accessed (64 kilobytes, if the offset is 16 bits).

The 16-bit offset may seem very small in relation to the size of current computer memories (which is why the 80386 expanded it to 32-bit). It could be worse: IBM System/360 mainframes only have an unsigned 12-bit offset. However, the principle of locality of reference applies: over a short time span, most of the data items a program wants to access are fairly close to each other. This addressing mode is closely related to the indexed absolute addressing mode. Example 1: Within a subroutine a programmer will mainly be interested in the parameters and the local variables, which will rarely exceed 64 KB, for which one base register (the frame pointer) suffices. If this routine is a class method in an object-oriented language, then a second base register is needed which points at the attributes for the current object (this or self in some high level languages). Example 2: If the base register contains the address of a composite type (a record or structure), the offset can be used to select a field from that record (most records/structures are less than 32 kB in size).

[edit] 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).

[edit] Implicit
+-----------------+ | clear carry bit | +-----------------+

The implied addressing mode[1], also called the implicit addressing mode[2], 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 or RAM location which could be the source or destination or both for arithmeticand so later computers need some other addressing mode to specify the source and destination of arithmetic. Many computers (such as x86 and AVR) have one special-purpose register called the stack pointer which is implicitly incremented or decremented when pushing or popping data from the stack, and the source or destination effective address is (implicitly) the address stored in that stack pointer. Most 32-bit computers (such as ARM and PowerPC) have more than one register which could be used as a stack pointerand so use the "register autoincrement indirect" addressing mode to specify which of those registers should be used when pushing or popping data from a stack. Some current computer architectures (e.g. IBM/390 and Intel Pentium) contain some instructions with implicit operands in order to maintain backwards compatibility with earlier designs. On many computers, instructions that flip the user/system mode bit, the interrupt-enable bit, etc. implicitly specify the special register that holds those bits. This simplifies the hardware necessary to trap those instructions in order to meet the Popek and Goldberg virtualization requirements -- on such a system, the trap logic does not need to look at any operand (or at the final effective address), but only at the opcode. A few CPUs have been designed where every operand is always implicitly specified in every instruction -- zero-operand CPUs.

You might also like