0% found this document useful (0 votes)
13 views

Chapter 2.3

Addressing modes allow instructions to reference operands in memory using different techniques depending on the opcode and mode field in the instruction, such as immediate values contained directly in the instruction, registers, displacement from a register, or memory addresses indirectly through a register. Common addressing modes include direct, indirect, register, register indirect, and displacement addressing. Displacement addressing combines direct and register indirect addressing by using the sum of a value from the instruction and a register value as the effective address.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Chapter 2.3

Addressing modes allow instructions to reference operands in memory using different techniques depending on the opcode and mode field in the instruction, such as immediate values contained directly in the instruction, registers, displacement from a register, or memory addresses indirectly through a register. Common addressing modes include direct, indirect, register, register indirect, and displacement addressing. Displacement addressing combines direct and register indirect addressing by using the sum of a value from the instruction and a register value as the effective address.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

ADDRESSING MODES

• Relatively small address field in instructions


• But a need to reference a large range of memory locations
• A variety of addressing techniques:
1. Immediate
2. Direct
3. Indirect
4. Register
5. Register indirect
6. Displacement
7. Stack

2
3
4
• All computer architectures support more than one of these addressing
modes.
• How does the process determine the addressing mode used in an
instruction?
• Different opcodes will use different addressing modes.
• One or more bits used in the instruction format (mode field). The
value of the mode field determines which addressing mode is to be used.

5
• Immediate Addressing
• The simplest form of addressing is immediate addressing
• The operand value is present in the instruction
• Operand = A
• Can be used to define and use constants or set initial values of variables.
• Typically, the number will be stored in twos complement form; the leftmost bit
of the operand field is used as a sign bit.
• Advantage of immediate addressing:
• No memory reference other than the instruction fetch is required to obtain
the operand
• saving one memory or cache cycle in the instruction cycle.
• Disadvantage: the size of the number is limited to the size of the address field,
which is small compared with the word length.

6
• Direct Addressing
• A very simple form of addressing
• The address field contains the effective address of the operand:
• EA = A
• Disadvantage: provides only a limited address space.
• Indirect Addressing
• With direct addressing:
• length of the address field < word length => limiting the address range
• One solution is to have the address field refer to the address of a word in memory,
• This in turn contains a full-length address of the operand.
• This is known as indirect addressing:
• EA = (A), ( ) stands for “contents of”

7
• Advantage: for a word length of N, an address space of 2N is available.

• Disadvantage: instruction execution requires two memory references to fetch the


operand:
• one to get its address and another to get its value.
• Register Addressing
• similar to direct addressing.
• Difference: address field refers to a register rather than a main memory address:
• EA = R
• That is: if the contents of a register address field in an instruction is 5, then the
operand value is contained in R5.

8
• If n-bits are used for the address field that references registers

• 2n registers can be referenced.

• Typically n is 3 to 5 bits

• Hence a total of 8 to 32 general-purpose registers can be referenced.

• Registers are used for operands that remain in use for multiple operations. (for
example for intermediate results).

• It would be wasteful if every operand is brought into a register from main memory,
operated on once, and then returned to main memory.

9
• Register Indirect Addressing

• Analogous to indirect addressing.

• Difference: address field refers to a register.

• EA = (R)

• The advantages and limitations of register indirect addressing are the same as for
indirect addressing.

• In both cases, the address space limitation (limited range of addresses) of the
address field is overcome by having that field refer to a word length location
containing an address.

• In addition, register indirect addressing uses one less memory reference than
indirect addressing. 10
• Displacement Addressing
• A very powerful mode of addressing combines the capabilities of direct
addressing and register indirect addressing.
• It is known by a variety of names depending on the context of its use, but the
basic mechanism is the same.
• We will refer to this as displacement addressing:
• EA = A + (R)
• Displacement addressing requires that the instruction have two address fields, at
least one of which is explicit.
• The value contained in one address field (value = A) is used directly.
• The other address field, or an implicit reference based on opcode, refers to a
register whose contents are added to A to produce the effective address.
11
• Displacement Addressing

• A very powerful mode of addressing

• Combines the capabilities of direct addressing and register indirect


addressing.
• EA = A + (R)

• Requires the instruction to have two address fields:

• The value contained in one address field (value = A) is used directly.

• The other address field, or an implicit reference based on opcode, refers to


a register whose contents are added to A to produce the effective address.

12
• Three common uses of displacement addressing:
• Relative addressing
• Base-register addressing
• Indexing
• RELATIVE ADDRESSING (also called PC-relative addressing)

• The implicitly referenced register is the program counter (PC).

• That is, the next instruction address is added to the address field to produce
the EA.
• Typically, the address field is treated as a twos complement number for this
operation.
• Thus, the effective address is a displacement relative to the address of the
current instruction. 13
• BASE-REGISTER ADDRESSING

• Interpreted as follows:

• The referenced register contains a main memory address.

• The address field contains a displacement (usually an unsigned integer


representation) from that address.

• The register reference may be explicit or implicit. Either a single segment-base


register is employed and is used implicitly or the programmer has to choose a
register to hold the base address of a segment, and the instruction must reference it
explicitly.
• In this latter case, if the length of the address field is K and the number of possible
registers is N, then one instruction can reference any one of N areas of 2K words.
14
• INDEXING
• Interpreted as follows:
• The address field references a main memory address, and
• the referenced register contains a positive displacement from that address.
• Just the opposite of the interpretation for base-register addressing.
• Because the address field is considered to be a memory address in indexing, it
generally contains more bits than an address field in a comparable base-register
instruction.
• But the method of calculating the EA is the same for both base-register addressing
and indexing.
• And, in both cases, the register reference is sometimes explicit and sometimes
implicit (for different processor types).

15
• An important use of indexing is to provide an efficient mechanism for performing iterative
operations.

• For example:

• Consider a list of numbers stored starting at location A.

• Suppose that we would like to add 1 to each element on the list.

• We need to fetch each value, add 1 to it, and store it back.

• The sequence of effective addresses that we need is A, A + 1, A + 2, . . . , up to the last


location on the list.
• With indexing, this is easily done.

• The value A is stored in the instruction’s address field, and the chosen register, called an
index register, is initialized to 0.
16
• After each operation, the index register is incremented by 1.
• Because index registers are commonly used for such iterative tasks, it is typical that
there is a need to increment or decrement the index register after each reference to it.

• Because this is such a common operation, some systems will automatically do this as
part of the same instruction cycle.

• This is known as autoindexing.


• If certain registers are devoted exclusively to indexing, then autoindexing can be
invoked implicitly and automatically.
• If general-purpose registers are used, the autoindex operation may need to be signaled
by a bit in the instruction.
• Autoindexing using increment can be depicted as follows.
• EA = A + (R)
• (R)  (R) + 1
17
• In some machines, both indirect addressing and indexing are provided, and it is
possible to employ both in the same instruction.
• There are two possibilities: the indexing is performed either before or after the
indirection.
• If indexing is performed after the indirection, it is termed postindexing:
• EA = (A) + (R)
• First, the contents of the address field are used to access a memory location
containing a direct address.
• This address is then indexed by the register value.

18
• With preindexing, the indexing is performed before the indirection:
• EA = (A + (R))
• An address is calculated as with simple indexing.
• In this case, the calculated address contains not the operand, but the address of the
operand.
• An example of the use of this technique is to construct a multiway branch table.
• At a particular point in a program, there may be a branch to one of a number of
locations depending on conditions.
• A table of addresses can be set up starting at location A.
• By indexing into this table, the required location can be found.

19
• Stack Addressing

• A stack is a linear array of locations.

• It is also referred to as a pushdown list or last-in-first-out queue.

• The stack is a reserved block of locations.

• Items are appended to the top of the stack so that, at any given time, the block is
partially filled.

• Associated with the stack is a pointer whose value is the address of the top of the stack.

• Alternatively, the top two elements of the stack may be in processor registers.

20
• In this case, the stack pointer references the third element of the stack.

• The stack pointer is maintained in a register.

• Hence, references to stack locations in memory are register indirect addresses.

• The stack mode of addressing is a form of implied addressing.

• The machine instructions need not include a memory reference but implicitly
operate on the top of the stack.

21
ASSEMBLY LANGUAGE
• A processor can understand and execute machine instructions.

• Such instructions are simply binary numbers stored in the computer.

• To program directly in machine language, then the program has to be entered as


binary data.

• Consider the statement

N=I+J+K

• Suppose we wished to program this statement in machine language and to


initialize I, J, and K to 2, 3, and 4, respectively.
22
Cont.…

23
Cont.…
• The program starts in location 101 (hexadecimal).
• Memory is reserved for the four variables starting at location 201.
• The program consists of four instructions:
• Load the contents of location 201 into the AC.
• Add the contents of location 202 to the AC.
• Add the contents of location 203 to the AC.
• Store the contents of the AC in location 204.
• This is clearly a tedious and very error-prone process.
• A slight improvement is to write the program in hexadecimal rather than binary
notation. Shown in (b).

24
Cont.…
• We could write the program as a series of lines.
• Each line contains the address of a memory location and the hexadecimal code of
the binary value to be stored in that location.
• Then we need a program that will accept this input, translate each line into a
binary number, and store it in the specified location.
• For more improvement, we can make use of the symbolic name or mnemonic of
each instruction.
• This results in the symbolic program shown in (c).
• Each line of input still represents one memory location.
• Each line consists of three

25
LMC (Little Man Computer)
LMC Instruction Set
Example:
• List of instructions (and addresses they are stored at) to accept two number from
input, add them and output result Address Instruction

Address Instruction

00 INP

01 STA 99

02 INP

03 ADD 99

04 OUT

05 HLT
Cont.….
INP Input a number and put it in the accumulator

STA Store the number in the accumulator in memory slot 99

INP Input a number and put it in the accumulator

ADD Add the number in memory slot


99 to the number in the accumulator

OUT Output the number which is now in the accumulator

HLT Halt

You might also like