You are on page 1of 17

Addressing mode

• In an instruction opcode & operands ( no of addresses)


are mentioned.
• Once we have determined the number of addresses
contained in an instruction, the manner in which each
address field specifies memory location must be
determined i.e. how to specify operands in an
instruction should be determined.
• So addressing modes have been devised.
• These are the set of syntaxes or methods used to specify
a memory address in an instruction.
Addressing mode
Common addressing techniques are:
– Immediate
– Direct
– Indirect
– Register
– Register indirect
– Displacement
– Relative
– Base register
– Indexing
– stack
Addressing mode
• All computer architecture provide more than one of
these addressing modes.
• Different opcode use different addressing modes.
• One or more bits in the instruction format can be used
as a ‘mode field’.
• Value of mode field determines which addressing mode
is to be used.
Immediate Addressing

• Simplest form of addressing


• The operand doesn’t specifies address, but operand
value is present in the instruction.
Operand =A
• No memory reference to fetch data
• Fast, no memory access to bring the operand
• Size of the operand (thus its range of values) is
limited
Direct Addressing
Instruction Memory
Opcode Address A

Operand

• EA = A
• Instruction includes the a memory address
• No calculations are required. Requires only one additional memory
reference to fetch the operand
• Address is a constant at run time but data itself can be changed during
program execution
• Provides a limited address space
Indirect Addressing
Instruction Memory
Opcode Address A

Pointer to operand
• Starts like the direct mode, but
it makes an extra memory
access. The address specified operand
in the instruction is not the
address of the operand, it is the
address of a memory location
that contains the address of the
operand.
• Two memory accesses are required
» The first to fetch the effective address
» The second to fetch the operand itself
• EA=(A)
Register Addressing
Instruction Registers
Opcode Register Address R

Operand

• EA=R
• It specifies a register instead a memory address
• No memory access
• Very fast execution
• Very limited address space
Register indirect Addressing
Instruction Registers Memory
Opcode Register Address R
Pointer to
operand

Operand

• EA = ( R )
• Register contains the address of the operand in the memory
• Register R , contains value which represents the address of
the operand in the memory
• One fewer memory access than indirect addressing
Displacement addressing
Instruction
Memory
Opcode Register R Address A

Pointer to
Operand + Operand

Registers

• Effective Address = A + (content of R)


• Address field hold two values
– A = base value
– R = register that holds displacement
– or vice versa
Relative addressing
• Also called as PC-relative addressing, as implicitly referenced register is
Program Counter (PC)
• It is a particular case of the displacement addressing, where the register
is the program counter
• Effective Address = A + (PC)
• Thus Effective address is a displacement relative to the address of the
instruction
• If memory references are relatively ear to the instruction being executed,
then the use of this addressing saves address bits in the instruction.
• E.g. Consider that the address A is 5 and the next instruction is at
location 12, so the operand is actually located at (12 +5) 17; the
instruction loads the operand at address 17 and stores it in the CPU’s
accumulator
Indexed addressing
• Address field references a main memory address &
referenced register contains a positive displacement
from that address.
• A acts as a base
• R acts as displacement
• Use of indexing is to provide an efficient
mechanism for performing iterative operations.
• Good for accessing arrays
Base-register addressing

• R holds a main memory address (acts as Base)


• A holds displacement which is usually an unsigned
integer representation
• Effective Address = A + (R)
• Register reference may be explicit or implicit
• Convenient means of implementing segmentation
Stack Addressing
Instruction
• Stack is a linear array of
locations
• Also referred as Pushdown list
Implicit or last-in-first-out queue

Top of stack
register
• The machine instructions need not include a memory reference
but implicitly operate on the top of stack.
• Stack pointer is maintained in a register, so references to stack
locations in memory are in fact register indirect addresses.
Instruction formats (1)
• An instruction is represented as a binary value with specific
format, called the instruction code
• It is made out of different groups of bits, with different
significations:
– Opcode – represents the operation to be performed (it is the
instruction identifier)
– Operands – one, two or three represent the operands of the
operation to be performed
• A microprocessor can have one format for all the
instructions or can have several different formats
• An instruction is represented by a single instruction code
Instruction formats (2)
Instruction formats (3)
• Fewer operands translates into more instructions to
accomplish the same task
• The hardware required to implement the microprocessor
becomes less complex with fewer operands;
microprocessors whose instructions specify a fewer number
of operands can execute instructions more quickly than
those that specify more operands
• The example was simplified to show the difference between
three, two, one and zero operands instructions; in practice,
the instructions require many more bits than used in these
examples; an operand field may specify an arbitrary memory
address, rather than one of the four registers; this could
require 16, 32 or even more bits per operand

You might also like