memory

Memory Addressing Modes in Assembly

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

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.