Understanding the mov
Instruction
What is mov
?
In assembly, mov
stands for “move”, but it doesn’t actually move data — it copies data from one location to another.
It’s one of the most fundamental instructions in assembly language. You’ll use it very frequently in low-level programming.
Syntax
mov destination, source
- This copies the value from the source into the destination.
- The destination gets overwritten.
- The source remains unchanged.
Examples
1. Move an Immediate Value into a Register
mov eax, 5 ; eax now holds the value 5
2. Copy One Register’s Value to Another
mov ebx, eax ; ebx now holds whatever was in eax
3. Working with Smaller Parts of a Register
mov al, 0x78 ; sets the lowest byte of eax to 0x78mov ah, 0x56 ; sets the next byte (above al) to 0x56
Registers can be broken down like this:
EAX
is 32 bits (4 bytes)AX
is the lower 16 bits ofEAX
AH
is the high byte ofAX
(bits 8–15)AL
is the low byte ofAX
(bits 0–7)
This allows fine-grained control to build or manipulate values flexibly.
Rules of mov
Here are some important constraints when using mov
:
- You cannot move data directly from one memory location to another:
; Validmov eax, [value]mov [value], eax
; Invalidmov [a], [b] ; not allowed
- The source and destination must be the same size:
; Validmov al, 1 ; both are 8 bits
; Invalidmov ax, eax ; 16-bit to 32-bit mismatch
Register Breakdown
The general-purpose registers can be broken into smaller parts for byte-level manipulation:
Name | Size | Description |
---|---|---|
EAX | 32 bits | Full register |
AX | 16 bits | Lower half of EAX |
AH | 8 bits | High byte of AX (bits 8–15) |
AL | 8 bits | Low byte of AX (bits 0–7) |
This same pattern applies to EBX
, ECX
, and EDX
.
Practice Challenges Using Only mov
Now that you understand the mov
instruction and register structure, here are some challenges to test your understanding.
You may only use mov
instructions to solve them.
Easy Challenges
1. Fill a Register Byte by Byte
Use mov
to set EAX
to the value 0x12345678
by assigning values to AH
and AL
.
You are not allowed to directly assign the full value to EAX
.
2. Copy and Reconstruct
You are given:
mov eax, 0xCAFEBABE
Use mov
to:
- Copy the value of
AL
intoBL
- Set
BH
to0x42
Question: What is the final value of BX
?
3. Zero a Register
Use mov
to set EBX
to zero.
You are not allowed to use xor
or any other instruction.
Hard Challenges
1. Flip Bytes in a Register
You are given:
mov eax, 0x12345678
Use mov
instructions to:
- Copy
AL
intoAH
- Copy
AH
intoAL
(swap them)
After the operation, AX
should hold 0x7878
.
2. Set EAX
to 0x42424242
Using Only 8-bit Moves
Rules:
- You may not use
mov eax, ...
ormov ax, ...
- You must build the full 32-bit value using only
mov
instructions targeting 8-bit parts (AL
,AH
, etc.)
Hint:
You’ll need to copy intermediate results to other registers and then back into EAX
.
Summary
You now understand:
- What
mov
does (copying data, not moving it) - How to use
mov
with immediate values and registers - How registers like
EAX
can be broken into parts (AX
,AH
,AL
) - Basic restrictions of the
mov
instruction - How to solve problems using only
mov
and register logic
With this knowledge, you’re already thinking like a CPU.
Try solving the challenges and experiment further to reinforce what you’ve learned.
Challenge 2: Reverse 16-bit in AX
Using Only 8-bit Moves
You are given:
mov ax, 0xABCD
Your Task:
After the operations, the value in AX
must be:
0xCDAB
Constraints:
- Use only 8-bit
mov
instructions (AL
,AH
, etc.) - Do not use
mov ax, ...
orxchg
- Do not use
rol
,ror
,shl
, orshr
- You must manually swap the bytes in
AX
using only 8-bit moves
Challenge 3: Construct EAX = 0xDEADBEEF
Using Only 8-bit mov
Your Task:
Build the full 32-bit value in EAX
so that:
EAX == 0xDEADBEEF
Constraints:
- Use only 8-bit
mov
instructions (AL
,AH
,BL
, etc.) - Do not use
mov eax, ...
ormov ax, ...
- Do not use arithmetic or logical operations (
add
,or
, etc.) - Carefully place each byte into the correct part of
EAX
usingmov
to 8-bit registers