w1coding.comAll tutorials

Assembly Memory

Assembly lessons
  1. Environment Setup
  2. Introduction
  3. Syntax
  4. Datamovement
  5. Operators
  6. Control
  7. Loops
  8. Interupts
  9. Functions
  10. Memory
  11. System
  12. Debugging
  13. Macros
  14. Execution
  15. Floating
  16. Interupts
  17. Optimization
  18. Linking
  19. Inline
  20. Registers
  21. Bootloader
  22. Macros
  23. Stack
  24. Call
  25. Technique
  26. Responsive

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.