w1coding.comAll tutorials

Assembly Datamovement

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

Data Movement Instructions

Data movement instructions are used to transfer data between registers, memory, and immediate values.

Basic Instructions

  • mov: Moves data from a source to a destination.
  • push: Pushes data onto the stack.
  • pop: Pops data from the stack.
  • lea: Loads the address of a variable into a register.

Example: mov Instruction

section .data
    num1 db 10   ; Declare a byte variable with value 10
    num2 db 20   ; Declare another byte variable with value 20

section .text
    global _start

_start:
    mov al, [num1]  ; Load the value of num1 into AL register
    mov bl, [num2]  ; Load the value of num2 into BL register
    add al, bl      ; Add the two values
    mov [num1], al  ; Store the result back into num1
    

This example transfers data between memory and registers and performs an addition operation.

Example: Stack Operations

section .text
    global _start

_start:
    push 5          ; Push 5 onto the stack
    push 10         ; Push 10 onto the stack
    pop rax         ; Pop the top value (10) into rax
    pop rbx         ; Pop the next value (5) into rbx
    

Stack operations are useful for saving and restoring data during function calls.