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

Addressing modes

Addressing modes in CO&AL

Uploaded by

muzammilsohail76
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Addressing modes

Addressing modes in CO&AL

Uploaded by

muzammilsohail76
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Computer Organization

and Assembly
Language
7-Addressing Modes
Outline
• Immediate
• Register
• Direct
• Indirect / Register indirect
• Base Address
• Indexed
• Base Indexed
• Implied
Immediate Addressing

• The simplest form of addressing is immediate addressing, in which the operand value is present in
the instruction
• This mode 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. When the operand is loaded into a data register, the sign bit is extended to the left to the
full data word size.
• In some cases, the immediate binary value is interpreted as an unsigned nonnegative
• integer.
• The advantage of immediate addressing is that no memory reference other than the instruction
fetch is required to obtain the operand, thus saving one memory or cache cycle in the instruction
cycle.
• The disadvantage is that the size of the number is restricted to the size of the address field, which,
in most instruction sets, is small compared with the word length.
• Operand = A
Direct Addressing

• A very simple form of addressing is direct addressing, in which the


address field contains the effective address of the operand:
• The technique was common in earlier generations of computers but is
not common on current architectures. It requires only one memory
reference and no special calculation. The obvious limitation is that it
provides only a limited address space.
• EA = A
Indirect Addressing
• With direct addressing, the length of the address field is usually less than the
word length, thus limiting the address range. One solution is to have the
address field refer to the address of a word in memory, which in turn contains a
full-length address of the operand. This is known as indirect addressing: EA =
(A)
• The parentheses are to be interpreted as meaning contents of.
• The advantage of this approach is that for a word length of N, an address space
of 2N is now available.
• The disadvantage is that instruction execution requires two memory references
to fetch the operand: one to get its address and a second to get its value.
• Although the number of words that can be addressed is now equal 2N to the
number of different effective addresses that may be referenced at any one time
is limited to 2K where K is the length of the address field.
Register Indirect Addressing
• Just as register addressing is analogous to direct addressing, register
indirect addressing is analogous to indirect addressing.
• In both cases, the only difference is whether the address field refers to a
memory location or a register. Thus, for register indirect address, EA =
(R)
• The advantages and limitations of register indirect addressing are
basically 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 wordlength location containing
an address. In addition, register indirect addressing uses one less
memory reference than indirect addressing.
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.
• We will describe three of the most common uses of displacement addressing:
• Relative addressing
• Base-register addressing
• Indexing
RELATIVE ADDRESSING
• For 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 instruction.
BASE-REGISTER ADDRESSING
• For base-register addressing, the interpretation is the following:
• The referenced register contains a main memory address, and the
address field contains a displacement (usually an unsigned integer
representation) from that address. The register reference may be
explicit or implicit.
INDEXING
• For indexing, the interpretation is typically the following: The address
field references a main memory address, and the referenced register
contains a positive displacement from that address. Note that this
usage is just the opposite of the interpretation for base-register
addressing.
• Of course, it is more than just a matter of user interpretation. 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.
Basic Addressing Modes
Stack Addressing
• A stack is a linear array of locations. It is sometimes 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, in
which case the stack pointer references the third element of the stack. The stack
pointer is maintained in a register. Thus, references to stack locations in memory
are in fact 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.
8086 Addressing Modes
• For the immediate mode, the operand is included in the instruction. The operand can be a byte,
word, or doubleword of data.
• For register operand mode, the operand is located in a register. For general instructions, such as
data transfer, arithmetic, and logical instructions, the operand can be one of the 32-bit general
registers (EAX, EBX, ECX,EDX,ESI, EDI, ESP, EBP), one of the 16-bit general registers (AX, BX, CX,
DX, SI, DI, SP, BP), or one of the 8- bit general registers (AH, BH, CH, DH, AL, BL, CL, DL). There are
also some instructions that reference the segment selector registers (CS, DS, ES, SS, FS, GS).
• The remaining addressing modes reference locations in memory. The memory location must be
specified in terms of the segment containing the location and the offset from the beginning of
the segment. In some cases, a segment is specified explicitly; in others, the segment is specified
by simple rules that assign a segment by default.
• In the displacement mode, the operand’s offset (the effective address is contained as part of the
instruction as an 8-, 16-, or 32-bit displacement.
• With segmentation, all addresses in instructions refer merely to an offset in a segment.
• The displacement addressing mode is found on few machines because, as
mentioned earlier, it leads to long instructions. In the case of the x86, the
displacement value can be as long as 32 bits, making for a 6-byte
instruction.
• Displacement addressing can be useful for referencing global variables.
• The remaining addressing modes are indirect, in the sense that the address
portion of the instruction tells the processor where to look to find the
address.
• The base mode specifies that one of the 8-, 16-, or 32-bit registers contains
the effective address. This is equivalent to what we have referred to as
register indirect addressing.
Register Addressing mode

• Source and destination both are registers


• What will happen for MOV AX,BX
Immidiate Addressing Mode
Direct Addressing Mode

Offset=
4321

To calculate physical
address
PA=DS* 10H +Offset PA=DS* 10H +Offset
Memory Indirect Addressing Mode
• In this offset is given in either BX, SI or DI
• Default segment is DS or ES
• MOV AL,[SI]

PA=DS* 10H +Offset


Memory Based Addressing Mode
• Effective address of memory is take from base registers like BX,BP
• For BX by default segment is Data segment
Example
MOV DL,[BX]

PA=DS* 10H +[BX]


Memory Indexed Addressing Mode
• Effective address of memory is take from base registers like SI,DI
• For SI by default segment is Data segment
• For DI by default segment is Extra segment

Example
MOV DL,[SI]
EA=1002

PA=DS* 10H +[SI]


Based-Indexed Addressing
Effective address is sum of base and index register

Example

MOV CH,[BX+SI]

EA=5321

PA=DS* 10H +[BX+SI]


BX=1000h,SI=4321h
Relative Base Addressing Mode
Operand address is calculated using one of the base register and 8-bit
or 16-bit displacement
Example
MOV CX,[BX+04H]
PA=DS* 10H +[BX+04H]
EA=1004

PA=DS* 10H +[BX+04H]


BX=1000H,
Relative Index Addressing Mode
Operand address is calculated using one of the base register and 8-bit
or 16-bit displacement
Example
MOV CX,[SI+04H]
PA=DS* 10H +[SI+04H]
Relative Base Index Addressing
Mode
Operand address is calculated using one of the base and index register
and 8-bit or 16-bit displacement

Example
MOV CX,[BX+SI+04H]
PA=DS* 10H +[BX+SI+04H]
Implied Addressing Mode
• Operands are implied or not specified in instruction.
• STC Set(ST) Carry(C) makes 0 1
• CLD Clear(CL) Direction(D) makes 1 0

You might also like