100% found this document useful (1 vote)
206 views21 pages

Chapter 2 - Addressing Modes

The document discusses different addressing modes used in real mode on x86 processors, including: 1) Real mode allows accessing the first 1MB of memory using segment and offset addresses, with segments always being 64KB in size. 2) Common addressing modes include register, immediate, direct, register indirect, base+index, register relative, and base relative+index addressing. 3) Program memory addressing modes include direct, relative, and indirect jumping, with relative jumps using a displacement relative to the instruction pointer to jump within the current code segment.

Uploaded by

Dawit Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
206 views21 pages

Chapter 2 - Addressing Modes

The document discusses different addressing modes used in real mode on x86 processors, including: 1) Real mode allows accessing the first 1MB of memory using segment and offset addresses, with segments always being 64KB in size. 2) Common addressing modes include register, immediate, direct, register indirect, base+index, register relative, and base relative+index addressing. 3) Program memory addressing modes include direct, relative, and indirect jumping, with relative jumps using a displacement relative to the instruction pointer to jump within the current code segment.

Uploaded by

Dawit Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

ADDRESSING MODES

Lecture 2

Prepared by: Beimnet G

1
ADDRESSING MODES
Real mode memory (real memory, conventional
memory, DOS memory) exists at locations 00000H–
FFFFFH, the first 1M byte of the memory system,
and is present on all versions of the x86
microprocessors.
Real mode operation allows the microprocessor to
address only the first 1M byte of memory space
2
SEGMENTS AND OFFSETS
A combination of a segment address and an offset address
accesses a memory location in the real mode.
All real mode memory addresses must consist of a segment
address plus an offset address.
 The segment address, located within one of the segment registers,
defines the beginning address of any 64K-byte memory segment.
 The offset address selects any location within the 64K byte
memory segment.
Segments in the real mode always have a length of 64K bytes.
3
SEGMENT AND OFFSETS
In the real mode, each segment register is internally appended with a
0H on its rightmost end. This forms a 20-bit memory address, allowing it
to access the start of a segment.
Because of the internally appended 0H, real mode segments can begin
only at a l6-byte boundary in the memory system. This l6-byte boundary
is often called a paragraph.
Because a real mode segment of memory is 64K in length, once the
beginning address is known, the ending address is found by adding
FFFFH.
Note: Some addressing modes combine more than one register and an
offset value to form an offset address and values may exceed FFFFH.

4
SEGMENT AND OFFSETS
The microprocessor has a set of rules that apply to segments whenever
memory is addressed. These rules define the segment register and offset
register combination.
For example, the code segment register is always used with the
instruction pointer to address the next instruction in a program. And the
stack segment register is always used with either the stack pointer or the
base pointer.
Note that a memory segment can touch or even overlap if 64K bytes of
memory are not required for a segment.
The segment plus offset addressing scheme allows DOS programs to be
relocated in the memory system.

5
DATA ADDRESSING MODES
Register Addressing
Immediate Addressing
Direct Addressing
Register Indirect Addressing
Base plus index Addressing
Register-relative Addressing
Base relative-plus-index Addressing
6
DATA ADDRESSING MODES
The MOV instruction
MOV X,Y
MOV- opcode
X,Y- operands
X- destination
Y- source
MOV copies data in source location into destination location.
The operands could be any combination of registers or memory
locations but memory to memory transfer is not allowed.

7
REGISTER ADDRESSING
Register addressing transfers a copy of a byte or
word from the source register or contents of a
memory location to the destination register or
memory location. [Most common and easy]
 E.g. MOV AX,BX
Location should be of similar size
The CS register can never be the destination
address
8
IMMEDIATE ADDRESSING
Immediate addressing transfers the source, an
immediate byte or word into the destination register or
memory location.
E.g. MOV CH,3AH
The name immediate points to the fact that the data to
be copied is found immediately after the opcode.
Note: The immediate data is always a constant
9
DIRECT ADDRESSING
Direct addressing moves a byte or word between a
memory location addressing and a register. The instruction
set does not support a memory-to memory transfer, except
with the MOVS instruction.
Example: The MOV CX, LIST instruction copies the word-
sized contents of memory location LIST into register CX.

10
REGISTER INDIRECT ADDRESSING

Register indirect addressing transfers a byte or word between a register and a memory
location addressed by an index or base register. The index and base registers are BP, BX, DI,
and SI.
The [ ] symbols denote indirect addressing in assembly language.
Example: The MOV AX, [BX] instruction copies the word-sized data from the data segment
offset address indexed by BX into register AX.
For example, if register BX contains 1000H and the MOV AX,[BX] instruction executes, the
word contents of data segment offset address 1000H are copied into register AX. If the
microprocessor is operated in the real mode and , this instruction addresses a word stored at
memory bytes 2000H and 2001H, and transfers it into register AX. Note that the contents of
2000H are moved into AL and the contents of 2001H are moved into AH.
The data segment is used by default with register indirect addressing or any other addressing
mode that uses BX, DI, or SI to address memory. If the BP register addresses memory, the stack
segment is used by default.

11
BASE-PLUS-INDEX ADDRESSING
Base-plus-index addressing transfers a byte or word between a register and
the memory location addressed by a base register (BP or BX) plus an index
register (DI or SI).
Example: The MOV [BX+DI ], CL instruction copies the byte-sized contents of
register CL into the data segment memory location addressed by BX plus DI.
In the Intel 8086, this type of addressing uses one base register (BP or BX)
and one index register (DI or SI) to indirectly address memory. The base
register often holds the beginning location of a memory array, whereas the
index register holds the relative position of an element in the array.

12
REGISTER RELATIVE ADDRESSING
Register relative addressing moves a byte or word between a register and the
memory location addressed by an index or base register plus a displacement.
Example: MOV AX,[BX+4 ] or MOV AX,ARRAY[BX]. The first instruction loads AX
from the data segment address formed by BX plus 4. The second instruction loads AX
from the data segment memory location in ARRAY plus the contents of BX.
The displacement is a number added to the register within the [ ], as in the MOV
AL,[DI+2] instruction, or it can be a displacement is subtracted from the register, as in
MOV AL,[SI–l]. A displacement also can be an offset address appended to the front
of the [ ], as in MOV AL,DATA[DI]. Both forms of displacements also can appear
simultaneously, as in the MOV AL,DATA[ ] instruction. Both forms of the displacement
add to the base or base plus index register within the [ ] symbols.

13
BASE-RELATIVE-PLUS-INDEX ADDRESSING
Base relative-plus-index addressing transfers a byte or word between a
register and the memory location addressed by a base and an index register
plus a displacement.
The base relative-plus-index addressing mode is similar to base-plus-index
addressing, but it adds a displacement, besides using a base register and an
index register, to form the memory address.
Example: MOV AX, ARRAY[BX+DI] or MOV AX, [BX+DI+4]. These instructions
load AX from a data segment memory location. The first instruction uses an
address formed by adding ARRAY, BX, and DI and the second by adding BX,
DI, and 4.

14
ADDRESSING MODES- 2
Lecture 3

Prepared by: Beimnet G

15
PROGRAM MEMORY-ADDRESSING MODES
used with the JMP (jump) and CALL instructions
Has 3 forms:
 Direct
 Relative
 Indirect

16
DIRECT PROGRAM MEMORY ADDRESSING
The instructions for direct program memory addressing store the address
with the opcode
This mode is called direct addressing mode because the required
address is directly present in the instruction rather than being stored in
some register.
Ex: JMP [10000H]
JMP 4032H
This JMP instruction loads CS with 1000H and IP with 0000H to jump to
memory location 10000H for the next instruction
Note: The direct JMP can jump to any memory location in the memory
system and is therefore referenced as a far jump.
 An intersegment jump is a jump to any memory location withing the
memory system (could be between two different segments).
Usually, a label associated with a memory address in used in these
instructions instead of numeric addresses.
17
RELATIVE PROGRAM MEMORY ADDRESSING
The term relative means “relative to the instruction pointer (IP)”.
Ex: JMP [2]
This program skips the next 2 instructions (2 bytes of memory).
The jump could be forward or backward.
The next instruction to be executed in calculated by adding 2 to
the current value in the IP

18
RELATIVE PROGRAM MEMORY ADDRESSING
The jump value can be a 1-byte or 2-byte displacement.
A 1-byte displacement is used in SHORT jumps and a 2-byte
displacement is used in a NEAR jump.
A SHORT jump has a range of -128 to 127 bytes
A NEAR jump has a range of ± 32K bytes
Both types are intrasegment jumps; i.e. A jump withing the current code
segment.
The type of jump is selected automatically by the assembler and if the
displacement is too far the assemble uses the direct jump instead.
19
INDIRECT PROGRAM MEMORY ADDRESSING
Can use any 16-bit register (AX,BX,BP,DI…) or relative
register([BP],[BX],[DI],[SI]) or a relative register with a displacement.
JMP BX, where BX=1000H
The program execution jumps to offset address 1000H in the current
code segment.
JMP [BX]
Retrieve data at the location referenced by BX and use value to serve
as a displacement in the current code segment.
This jump is sometimes called an indirect-indirect jump.
Other possible formats: JMP TABLE[BX], JMP [DI+2]

20
STACK MEMORY ADDRESSING MODES
Used to store return addresses used by procedures and other temporary
data.
Data moved into the stuck with the PUSH instructions and removed from the
stack using the POP instruction.
The stack is maintained by the stack segment register (SS) and the stack
pointer register (SP).
PUSH AX
When a push instruction is executed the lower byte is placed at the current
SP-1 location and the higher byte is stored at the SP-2 location and SP is
decremented by 2 point to the new top of stack.
POP BX
21

You might also like