An instruction at the ISA level of the computer consists of at least three parts, opcode, source address[es], destination address. When an instruction is executed on a cpu, it always involves at least one register as either the source or target and additional sources or targets to complete the instruction. This additional information is know as the effective address. The effective address may be a location in main memory, an i/o port, or another register.
On some systems, both the primary register and effective address must be specified as operands. On others the primary register is implied by the instruction opcode.
There are a small number of primary catagories for grouping instructions by their effective address. However, many actual instructions combine two or more of these catagories to create more complex and useful features. Additionally, not all catagories are available in their primary form on all cpu designs.
Implied - The effective address is implied by (is part of) the opcode itself. Implied instructions usually consist of only the instruction opcode. The registers and/or memory involved is known by the cpu and will be accessed automatically. Examples might be an instruction that increments the counter register by a predefined value or sets or tests a CPU condition register.
Stack addressing - The effective address is found in a dedicated register implied by the opcode and is auto-adjusted as data is pushed or pulled from stack. A stack instruction may imply a second register as the complementry source or destination of the data being moved or may allow user to specify the second argument. Stack addressing can sometimes qualify as a specific type of implied addressing.
It is considred different because of the automatic adjustment of the stack pointer and the accompanying set of commands specifically related to it. Examples : push, pop, call (subroutine), return (return from subroutine).
Immediate - The effective address is the address of instruction's operand. (memory pointed to by the instruction pointer). The effective address is the location of an operand of the instruction, since the operand is the data to be accessed. Immediate instructions use their operand to hold the data needed to complete the instruction.
The advantage of immediate immediate addressing is that all data is retrieved with the completion of the operand fetch.
A disadvantage is that the value retrieved is hard coded and non-changeable since modification of code once the code is running is consider improper and in many systems impossible. Another disadvantage is the size of the data allowed in the operand. A cpu may be able to fetch 16 or 32 bit data values when reading from memory, but an immediate operand may be restricted to 8 bits or some other value smaller than the full register size.
Register - All effective addresses (both source and destination) are registers named in the operand. The effective address(es) is/are the named registers involved in the action. Actions between registers are the fastest to accomplise and are highly favored in RISC arcthitectures.
Direct - The effective address is a memory address specified in the operand. This address indicates the starting location of the data to be accessed. Some systems have different opcodes if the address in the operand can be retrieved with a single read rather that requiring several reads of the operand field. This may be referred to as a zero page or near address.
A primary advantage of this addressing mode is use of a quick, direct path to the data of insterest.
A dis-advangage is that the address is permanently coded in the instruction.
Relative - The effective address is found by adding the operand treated as a signed offset to the program counter. In most cases, relative addressing is used with commands that modify the program counter, such as conditinal branch statements, so the effective address, once calculated, is stored back in the program counter.
A major advantage of relative addressing is found in relation to multitasking systems. Since any branches are relative to the current instruction pointer, the code can be loaded anywhere in main memory and it self-corrects for the address offsets.
The primary disadvantage of relative addressing is that the operand is seldom large enough to represent the full address range, thus limiting the branching distance or requiring a different branch technique for branching of a different magnitude.
Indirect - The effective address is stored in a register (register indirect) or memory location (memory indirect) specified by the operand - essentially a pointer.
The advantage of this is the ability to change the memory pointed during program execution. It is very useful when processing arrays of data.
Register Indirect is also useful in multi-tasking systems because the 'pointer' can be adjusted for the block of memory the code is loaded into.
Disadvantages are (1) Several fetches are required to arrive at the data of interest. (2) In the case of register indirect, cpu registers acting as pointers are not available for other tasks. I.E. you want a CPU with many registers.
Indexed - The effective address is a combination of a specified address or register contents and a second register (the index) Indexing allows for an adjustable pointer while keeping the initial start location.
In some implementations, the index register is not capable of representing the full address space, thus limiting their range. And they are treated as unsigned values, thus providing only positive incrementing from the base address.
Additionally, some systems, such as systems supporting vector functions, will scale the index. So, index incremented by one but when used multiplied by 16.
* It is not uncommon to find systems that allow for indirect and index functions to be combined for a more flexible addressing mode.
Displacement - The effective address is a combination of address stored in a named register (or registers) and a hard coded offset value. Displacement is always a positive value. The displacement value is an offset that is almost always a value much smaller that a legal address in possible address range of the system (often between 256 and 4K). However, the indirect register may be capable of holding any value in the full address range.
Commands can also be classified by their action or what are they trying to accomplish.