You are on page 1of 5

The most common names for addressing modes (names may differ among architectures)

Addressing
Example
Meaning
When used
modes
Instruction
Register
Add R4,R3
R4 <- R4 + R3
When a value is in a register
Immediate
Add R4, #3
R4 <- R4 + 3
For constants
Add R4,
Displacement
R4 <- R4 + M[100+R1] Accessing local variables
100(R1)
Register
Accessing using a pointer or a
Add R4,(R1) R4 <- R4 + M[R1]
deffered
computed address
Useful in array addressing:
Add R3, (R1 +
Indexed
R3 <- R3 + M[R1+R2] R1 - base of array
R2)
R2 - index amount
Direct
Add R1, (1001) R1 <- R1 + M[1001]
Useful in accessing static data
Memory
Add R1,
If R3 is the address of a pointer p,
R1 <- R1 + M[M[R3]]
deferred
@(R3)
then mode yields *p
Useful for stepping through arrays in
AutoR1 <- R1 +M[R2]
a loop.
Add R1, (R2)+
increment
R2 <- R2 + d
R2 - start of array
d - size of an element
Same as autoincrement.
AutoR2 <-R2-d
Add R1,-(R2)
Both can also be used to implement a
decrement
R1 <- R1 + M[R2]
stack as push and pop
Used to index arrays. May be applied
Add R1,
R1<Scaled
to any base addressing mode in some
100(R2)[R3]
R1+M[100+R2+R3*d]
machines.

Notation:
<- - assignment
M - the name for memory:
M[R1] refers to contents of memory location whose address is given by the contents
of R1
Immediate and displacement addressing modes dominate addressing mode usage.
The major question for displacement-style addressing mode is that of the range of
displacement used. Choosing the displacement field size is important because it
directly affects instruction length. According to measurements taken on the data
access on a GPR architecture using SPEC benchmarks displacement values are widely
distributed.

IMPLEMENTATION OF VARIABLES AND CONSTANTS


Variables and constants are the simplest data types and are found in almost every computer
program. A variable is represented by allocating a register or a memory location to hold its value.
Thus, the value can be changed as needed using appropriate instructions.
1. Register addressing mode - The operand is the contents of a processor register; the name
(address) of the register is given in the instruction.
Example: MOVE R1,R2
This instruction copies the contents of register R2 to R1.
2. Absolute addressing mode - The operand is in a memory location; the address of this location
is given explicitly in the instruction. (In some assembly languages, this mode is called Direct.)
Example: MOVE LOC,R2
This instruction copies the contents of memory location of LOC to register R2.
3. Immediate addressing mode - The operand is given explicitly in the instruction.
Example: MOVE #200 , R0
The above statement places the value 200 in the register R0. A common convention is to
use the sharp sign (#) in front of the value to indicate that this value is to be used as an immediate
operand.
INDIRECTION AND POINTERS
In the addressing modes that follow, the instruction does not give the operand or its address
explicitly. Instead, it provides information from which the memory address of the operand can be
determined. We refer to this address as the effective address (EA) of the operand.
4. Indirect addressing mode - The effective address of the operand is the contents of a register or
memory location whose address appears in the instruction.
Example Add (R2),R0
Register R2 is used as a pointer to the numbers in the list, and the operands are accessed indirectly

through R2. The initialization section of the program loads the counter value n from memory
location N into Rl and uses the Immediate addressing mode to place the address value NUM 1,
which is the address of the first number in the list, into R2.
INDEXING AND ARRAY
It is useful in dealing with lists and arrays.
5. Index mode - The effective address of the operand is generated by adding a constant value to
the contents of a register.
The register used may be either a special register provided for this purpose, or, more
commonly; it may be anyone of a set of general-purpose registers in the processor. In either case, it
is referred to as an index register. We indicate the Index mode symbolically as X(Ri).
Where X denotes the constant value contained in the instruction and Ri is the name of the
register involved. The effective address of the operand is given by EA = X + [Ri]. The contents of
the index register are not changed in the process of generating the effective address.
RELATIVE ADDRESSING
We have defined the Index mode using general-purpose processor registers. A useful
version of this mode is obtained if the program counter, PC, is used instead of a general purpose
register. Then, X(PC) can be used to address a memory location that is X bytes away from the
location presently pointed to by the program counter. Since the addressed location is identified
''relative'' to the program counter, which always identifies the current execution point in a program,
the name Relative mode is associated with this type of addressing.
6.Relative mode - The effective address is determined by the Index mode using the program
counter in place of the general-purpose register Ri.
This mode can be used to access data operands. But, its most common use is to specify the target
address in branch instructions. An instruction such as Branch>O LOOP causes program
execution to go to the branch target location identified by the name LOOP if the branch condition

is satisfied. This location can be computed by specifying it as an offset from the current value of
the program counter. Since the branch target may be either before or after the branch instruction,
the offset is given as a signed number.
ADDITIONAL MODES
The two additional modes described are useful for accessing data items in successive
locations in the memory.
7. Autoincrement mode - The effective address of the operand is the contents of a register
specified in the instruction. After accessing the operand, the contents of this register are
automatically incremented to point to the next item in a list.
We denote the Autoincrement mode by putting the specified register in parentheses, to
show that the contents of the register are used as the effective address, followed by a plus sign to
indicate that these contents are to be incremented after the operand is accessed. Thus, the
Autoincrement mode is written as (Ri) +
As a companion for the Autoincrement mode, another useful mode accesses the items of a list in
the reverse order:
8. Autodecrement mode - The contents of a register specified in the instruction is first
automatically decremented and is then used as the effective address of the operand.
We denote the Autodecrement mode by putting the specified register in parentheses, preceded by a
minus sign to indicate that the contents of the register are to be decremented before being used as
the effective address. Thus, we write - (Ri)

You might also like