Lec04 Addressing Modes
Lec04 Addressing Modes
IT372
Microprocessors
Lec04 Addressing Modes
Introduction
1
3/19/2024
Introduction
Chapter Objectives
Upon completion of this chapter, you will be able to:
• Explain the operation of each data-addressing mode.
• Use the data-addressing modes to form assembly language statements.
• Explain the operation of each program memory-addressing mode.
• Use the program memory-addressing modes to form assembly and machine
language statements.
2
3/19/2024
3
3/19/2024
Figure 3–1 The MOV instruction showing the source, destination, and
direction of data flow.
• Figure 3–2 shows all possible variations of the data-addressing modes using
MOV.
• These data-addressing modes are found with all versions of the Intel
microprocessor.
• except for the scaled-index-addressing mode, found only in 80386 through Core2
• RIP relative addressing mode is not illustrated.
• only available on the Pentium 4 and Core2
in the 64-bit mode
4
3/19/2024
Register Addressing
10
5
3/19/2024
• In 80386 & above, extended 32-bit register names are: EAX, EBX, ECX, EDX,
ESP, EBP, EDI, and ESI.
• 64-bit mode register names are: RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI, and
R8 through R15.
• Important for instructions to use registers that are the same size.
• never mix an 8-bit \with a 16-bit register, an 8- or a 16-bit register with a 32-bit register
• this is not allowed by the microprocessor and results in an error when assembled
11
Figure 3–3 The effect of executing the MOV BX, CX instruction at the point
just before the BX register changes. Note that only the rightmost 16 bits of
register EBX change.
12
6
3/19/2024
13
Immediate Addressing
14
7
3/19/2024
15
16
8
3/19/2024
17
18
9
3/19/2024
19
20
10
3/19/2024
21
Direct Addressing
22
11
3/19/2024
23
Displacement Addressing
24
12
3/19/2024
25
26
13
3/19/2024
• The data segment is used by default with register indirect addressing or any
other mode that uses BX, DI, or SI to address memory.
• If the BP register addresses memory, the stack segment is used by default.
• these settings are considered the default for these four index and base registers
• For the 80386 and above, EBP addresses memory in the stack segment by
default.
• EAX, EBX, ECX, EDX, EDI, and ESI address memory in the data segment by
fault.
27
• When using a 32-bit register to address memory in the real mode, contents of
the register must never exceed 0000FFFFH.
• In the protected mode, any value can be used in a 32-bit register that is used
to indirectly address memory.
• as long as it does not access a location outside the segment, dictated by the access
rights byte
• In the 64-bit mode, segment registers are not used in address calculation; the
register contains the actual linear memory address.
28
14
3/19/2024
• In some cases, indirect addressing requires specifying the size of the data by
the special assembler directive BYTE PTR, WORD PTR, DWORD PTR, or
QWORD PTR.
• these directives indicate the size of the memory data addressed by the memory pointer
(PTR)
• The directives are with instructions that address a memory location through a
pointer or index register with immediate data.
• With SIMD instructions, the octal OWORD PTR, represents a 128-bit-wide
number.
29
30
15
3/19/2024
31
Base-Plus-Index Addressing
32
16
3/19/2024
• Figure 3–8 shows how data are addressed by the MOV DX,[BX + DI]
instruction when the microprocessor operates in the real mode.
• The Intel assembler requires this addressing mode appear as [BX][DI] instead
of [BX + DI].
• The MOV DX,[BX + DI] instruction is MOV DX,[BX][DI] for a program written for
the Intel ASM assembler.
33
34
17
3/19/2024
35
36
18
3/19/2024
37
38
19
3/19/2024
39
40
20
3/19/2024
41
42
21
3/19/2024
43
• Suppose a file of many records exists in memory, each record with many
elements.
• displacement addresses the file, base register addresses a record, the index register
addresses an element of a record
• Figure 3–13 illustrates this very complex form of addressing.
44
22
3/19/2024
45
Scaled-Index Addressing
46
23
3/19/2024
• Uses the 64-bit instruction pointer register in the 64-bit mode to address a
linear location in the flat memory model.
• Inline assembler program available to Visual does not contain any way of
using this mode or any other 64-bit addressing mode.
• The Microsoft Visual does not at present support developing 64-bit assembly
code.
47
Data Structures
48
24
3/19/2024
49
• Used for all jumps and calls by early microprocessor; also used in high-level
languages, such as BASIC.
• GOTO and GOSUB instructions
• The microprocessor uses this form, but not as often as relative and indirect
program memory addressing.
• The instructions for direct program memory addressing store the address
with the opcode.
50
25
3/19/2024
51
• This JMP instruction loads CS with 1000H and IP with 0000H to jump to
memory location 10000H for the next instruction.
• an intersegment jump is a jump to any memory location within the entire memory system
• Often called a far jump because it can jump to any memory location for the
next instruction.
• in real mode, any location within the first 1M byte
• In protected mode operation, the far jump can jump to any location in the 4G-byte
address range in the 80386 - Core2 microprocessors
52
26
3/19/2024
53
54
27
3/19/2024
Figure 3–15 A JMP [2] instruction. This instruction skips over the 2
bytes of memory that follow the JMP instruction.
55
56
28
3/19/2024
57
Figure 3–16 A jump table that stores addresses of various programs. The
exact address chosen from the TABLE is determined by an index stored with
the jump instruction.
58
29
3/19/2024
59
• Data are placed on the stack with a PUSH instruction; removed with a POP
instruction.
• Stack memory is maintained by two registers:
• the stack pointer (SP or ESP)
• the stack segment register (SS)
• Whenever a word of data is pushed onto the stack, the high-order 8 bits are
placed in the location addressed by SP – 1.
• low-order 8 bits are placed in the location addressed by SP – 2
60
30
3/19/2024
61
62
31
3/19/2024
• Note that PUSH and POP store or retrieve words of data—never bytes—in
8086 - 80286.
• 80386 and above allow words or doublewords to be transferred to and from
the stack.
• Data may be pushed onto the stack from any 16-bit register or segment
register.
• in 80386 and above, from any 32-bit extended register
• Data may be popped off the stack into any register or any segment register
except CS.
63
• PUSHA and POPA instructions push or pop all except segment registers, on
the stack.
• Not available on early 8086/8088 processors.
• 80386 and above allow extended registers to be pushed or popped.
• 64-bit mode for Pentium and Core2 does not contain a PUSHA or POPA instruction
64
32
3/19/2024
SUMMARY
• The MOV instruction copies the contents of the source operand into the
destination operand.
• The source never changes for any instruction.
• Register addressing specifies any 8-bit register (AH, AL, BH, BL, CH, CL, DH,
or DL) or any 16-bit register (AX, BX, CX, DX, SP, BP, SI, or DI).
65
(cont.)
SUMMARY
• The segment registers (CS, DS, ES, or SS) are also addressable for moving
data between a segment register and a 16-bit register/memory location or for
PUSH and POP.
• In the 80386 through the Core2 microprocessors, the extended registers also
are used for register addressing; they consist of EAX, EBX, ECX, EDX, ESP,
EBP, EDI, and ESI.
66
33
3/19/2024
(cont.)
SUMMARY
• In the 64-bit mode, the registers are RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI,
and R8 through R15.
• The MOV immediate instruction transfers the byte or word that immediately
follows the opcode into a register or a memory location.
• Immediate addressing manipulates constant data in a program.
67
(cont.)
SUMMARY
• In the 80386 and above, doubleword immediate data may also be loaded into
a 32-bit register or memory location.
• The .MODEL statement is used with assembly language to identify the start of
a file and the type of memory model used with the file.
• If the size is TINY, the program exists in the code segment, and assembled as
a command (.COM) program.
68
34
3/19/2024
(cont.)
SUMMARY
• If the SMALL model is used, the program uses a code and data segment and
assembles as an execute (.EXE) program.
• Direct addressing occurs in two forms in the microprocessor: direct
addressing and displacement addressing.
69
(cont.)
SUMMARY
• Both forms of addressing are identical except that direct addressing is used
to transfer data between EAX, AX, or AL and memory; displacement
addressing is used with any register-memory transfer.
• Direct addressing requires 3 bytes of memory, whereas displacement
addressing requires 4 bytes.
70
35
3/19/2024
(cont.)
SUMMARY
71
(cont.)
SUMMARY
72
36
3/19/2024
(cont.)
SUMMARY
73
(cont.)
SUMMARY
74
37
3/19/2024
(cont.)
SUMMARY
• Data structures are templates for storing arrays of data and are addressed by
array name and field.
• Direct program memory addressing is allowed with the JMP and CALL
instructions to any location in the memory system.
• With this addressing mode, the off-set address and segment address are
stored with the instruction.
75
(cont.)
SUMMARY
76
38
3/19/2024
(cont.)
SUMMARY
77
SUMMARY
• The PUSHA and POPA instructions transfer AX, CX, DX, BX, BP, SP, SI, and DI
between the stack and these registers.
• In 80386 and above, the extended register and extended flags can also be
transferred between registers and the stack.
• A PUSHFD stores the EFLAGS, whereas a PUSHF stores the FLAGS. POPA and
PUSHA are not available in 64-bit mode.
78
39