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 52. Copy One Register’s Value to Another
mov ebx, eax    ; ebx now holds whatever was in eax3. 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 0x56Registers can be broken down like this:
- EAXis 32 bits (4 bytes)
- AXis the lower 16 bits of- EAX
- AHis the high byte of- AX(bits 8–15)
- ALis the low byte of- AX(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 mismatchRegister 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, 0xCAFEBABEUse mov to:
- Copy the value of ALintoBL
- Set BHto0x42
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, 0x12345678Use mov instructions to:
- Copy ALintoAH
- Copy AHintoAL(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 movinstructions 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 movdoes (copying data, not moving it)
- How to use movwith immediate values and registers
- How registers like EAXcan be broken into parts (AX,AH,AL)
- Basic restrictions of the movinstruction
- How to solve problems using only movand 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, 0xABCDYour Task:
After the operations, the value in AX must be:
0xCDABConstraints:
- Use only 8-bit movinstructions (AL,AH, etc.)
- Do not use mov ax, ...orxchg
- Do not use rol,ror,shl, orshr
- You must manually swap the bytes in AXusing 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 == 0xDEADBEEFConstraints:
- Use only 8-bit movinstructions (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 EAXusingmovto 8-bit registers
 
  