datamovement

Data Movement Instructions in Assembly

Data Movement Instructions

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

Basic Instructions

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.