Data Movement Instructions (MOV, PUSH, POP)
Master instructions for moving data between registers, memory, and the stack, including MOV, PUSH, POP, and LEA.
Data on the Move
In assembly language, programs constantly move data around. This data lives in different places: inside the CPU's registers or in memory.
Understanding how to move data is fundamental. It's like learning to pick up and place objects before you can build anything complex.
- Registers: Fast, small storage directly inside the CPU.
- Memory: Slower, larger storage outside the CPU (RAM).
- Stack: A special area in memory used for temporary storage and function calls.
Moving Data with MOV
The MOV instruction is your primary tool for copying data. It stands for "move," but it actually copies the source to the destination, leaving the source unchanged.
Its basic form is MOV destination, source. The destination can be a register or a memory location, and the source can be an immediate value, a register, or a memory location.
Here's how to put a number directly into a register:
section .text
global _start
_start:
mov eax, 123 ; Copy the immediate value 123 into the EAX register
mov ebx, 456 ; Copy 456 into EBX
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80All lessons in this course
- Data Movement Instructions (MOV, PUSH, POP)
- Arithmetic and Logic Operations
- Conditional Jumps and Loops
- Bitwise and Shift Instructions