You are on page 1of 13

8.

Addressing Modes

Dr. Arun Kumar


Dept. of CSE, NIT RKL
Generating Memory Addresses
l How to specify the address of branch target?
l Can we give the memory operand address
directly in a single Add instruction in the loop?
l Use a register to hold the address of NUM1;
then increment by 4 on each pass through
the loop.
Addressing Modes
Opcode Mode ...

l Implied/Implicit:
l AC (Accumulator) is implied in “ADD M[AR]” in
“One-Address” instruction.
l TOS is implied in “ADD” in “Zero-Address”
instruction.
l Immediate:
l The use of a constant in “MOV R1, 5”,
i.e. R1 ← 5
l Register:
l Indicate which register holds the operand
Addressing Modes
l Register Indirect:
l Indicate the register that holds the number of the
register that holds the operand R1
MOV R1, (R2)
R2 = 3

l Direct Address: R3 = 5

l Use the given address to access a memory


location
Addressing Modes
l Indirect Address:
l Indicate the memory location that holds the
address of the memory location that holds the
data
AR = 101

100
101 0 1 0 4
102
103
104 1 1 0 A
Relative Addressing
l Relative mode – the effective address is determined
by the Index mode using the program counter in
place of the general-purpose register.
l X(PC) – note that X is a signed number
l Branch>0 LOOP
l This location is computed by specifying it as an
offset from the current value of PC.
l Branch target may be either before or after the
branch instruction, the offset is given as a singed
num.
Addressing Modes

l Relative Address:
0
l EA = PC + Relative Addr 1
PC = 2 2

100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Indexing and Arrays
l Index mode – the effective address of the operand
is generated by adding a constant value to the
contents of a register.
l Index register
l X(Ri): EA = X + [Ri]
l The constant X may be given either as an explicit
number or as a symbolic name representing a
numerical value.
l If X is shorter than a word, sign-extension is needed.
Addressing Modes
l Indexed:
l EA = Index Register + Relative Addr

Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+

100
AR = 100
101
Could be Positive or
Negative 102 1 1 0 A
(2’s Complement) 103
104
Addressing Modes
l Base Register:
l EA = Base Register + Relative Addr

Could be Positive or AR = 2
Negative
(2’s Complement)
+

100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points to 103 0 1 0 7
the beginning of 104 0 0 5 9
an array
Additional Modes
l 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.
l (Ri)+. The increment is 1 for byte-sized operands, 2 for 16-bit
operands, and 4 for 32-bit operands.
l Autodecrement mode: -(Ri) – decrement first
Move N,R1
Move #NUM1,R2 Initialization
Clear R0
LOOP Add (R2)+,R0
Decrement R1
Branch>0 LOOP
Move R0,SUM

The Autoincrement addressing mode used in the program


Addressing Modes
Name Assembler syntax Addressing function
l The
different Immediate #V alue Operand = Value
ways in Register Ri EA = R i
which the Absolute (Direct) LOC EA = LOC
location of
Indirect (R i ) EA = [R i ]
an (LOC) EA = [LOC]
operand is
specified in Index X(R i) EA = [R i ] + X
an Base with index (R i ,R j ) EA = [R i ] + [R j ]
instruction Base with index X(R i,R j ) EA = [R i ] + [R j ] + X
are and offset
referred to Relative X(PC) EA = [PC] + X
as
addressing Autoincremen t (R i )+ EA = [R i ] ;
Incremen t R i
modes.
Autodecrement - (R i ) Decremen t R i ;
EA = [R i]
Thank You

You might also like