Memory Addressing Modes
Memory addressing modes define how instructions access data stored in memory or registers. Understanding these modes is crucial for efficient assembly programming.
Common Addressing Modes
- Immediate Addressing: The operand is a constant value.
- Register Addressing: The operand is in a register.
- Direct Addressing: The operand's memory address is specified.
- Indirect Addressing: The memory address is stored in a register.
- Indexed Addressing: A base address plus an index is used to calculate the effective address.
Examples
1. Immediate Addressing
mov rax, 5 ; Load the immediate value 5 into rax
2. Register Addressing
mov rax, rbx ; Copy the value of rbx into rax
3. Direct Addressing
section .data
num db 10 ; Define a byte in memory
section .text
mov al, [num] ; Load the value at memory address 'num' into AL
4. Indirect Addressing
section .bss
buffer resb 4 ; Reserve 4 bytes in memory
section .text
mov rsi, buffer ; Load the address of 'buffer' into RSI
mov byte [rsi], 42 ; Store 42 at the address in RSI
5. Indexed Addressing
section .data
array db 1, 2, 3, 4 ; Define an array
section .text
mov rsi, array ; Load the base address of 'array' into RSI
mov al, [rsi+2] ; Load the third element of the array into AL
Indexed addressing is useful for working with arrays and data structures.