MP 5
MP 5
Addressing Modes
Outline
• Machine language
• Instruction components and format
• Data-addressing modes
• Program memory-addressing modes
• Stack memory-addressing modes
• Sampling of addressing modes
3
Machine Language
• Machine language is the native binary code that the
microprocessor understands and uses as the instructions
that control its operation
• Interpretation of machine’s language allows debugging or
modification at the machine language level
• Microprocessor requires an assembler program, which
generates machine code
• the machine language instructions are too complex to generate by
hand
• Machine language instructions for the 8086-80486, vary in
length from 1 to as many as 13 bytes
• there are over 20000 variations of machine language instructions
4
Instruction Components
6
Data-Addressing Modes
• Register - transfers a copy of a byte, word, doubleword, or
quadword from the source register to the destination register
MOV BX, CX (64-bit) MOV RDX, RCX
Data-Addressing Modes(cont.)
Data-Addressing Modes(cont.)
Data-Addressing Modes(cont.)
Direct-Data Addressing
• There are two basic forms of direct data addressing:
• (1) direct addressing, which applies to a MOV between a memory
location and AL, AX, or EAX, and
• (2) displacement addressing, which applies to almost any
instruction in the instruction set
14
Base-Plus-Index Addressing
19
Base-Plus-Index Addressing
20
Instruction Components
OPCODE
32
Instruction Components
OPCODE
Instruction Components
MOD
• MOD field specifies the addressing mode for the selected
instruction and whether the displacement is present with
the specified addressing mode
MOD FUNCTION
00 no displacement
01 8-bit sign-extended displacement
MOD REG R/M
10 16-bit displacement
11 R/M is a register (register addressing
mode)
• If the MOD filed contains a 00, 01, or 10, the R/M field
selects one of the data memory-addressing modes, e.g.,
• MOV AL, [DI] (no displacement)
• MOV AL, [DI + 2] (8-bit displacement)
34
Instruction Components
REG & R/M in Register Assignment
000 AL AX EAX
001 CL CX ECX
010 DL DX EDX
011 BL BX EBX
100 AH SP ESP
101 CH BP EBP
110 DH SI ESI
111 BH DI EDI
35
Register Assignment
Example
• Consider 2 byte instruction 8BECh in the machine
language program (assuming 16-bit instruction mode)
Example
• Consider machine language instruction 8A15h
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 MOD is always 00
R/M is always 110
Byte 3 Byte 4
39
Immediate Instruction
• Consider an instruction: MOV word PTR[BX + 1000h],
1234h
Moves 1234h into the word-sized memory
location addressed by the sum of
OPCODE W MOD R/M 1000h, BX, and DS x 10h
1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 1
WORD PTR directive indicates to the
Byte 1 Byte 2 assembler that the instruction uses a word-sized
Displacement-low Displacement-high memory pointer
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(if the instruction moves a byte of immediate data,
then BYTE PTR directive is used.
Byte 3 Byte 4
The above directive are only needed when it is not
Data-low Data-high
clear if the operation is a byte or a word, e.g.,
0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 MOV [BX], AL clear a byte move
MOV [BX], 1 not clear, can be byte-, word, or
Byte 5 Byte 6 double word-sized move
should be for instance
MOV BYTE PTR [BX], 1
40
Note: MOV CS, ?? and POP CS Note that the opcode for this instruction is
are not allowed different for the prior MOV instructions
41