619 words
3 minutes
MOV Instructions

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 0x78
mov 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 of EAX
  • AH is the high byte of AX (bits 8–15)
  • AL is 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:
; Valid
mov eax, [value]
mov [value], eax
; Invalid
mov [a], [b] ; not allowed
  • The source and destination must be the same size:
; Valid
mov al, 1 ; both are 8 bits
; Invalid
mov ax, eax ; 16-bit to 32-bit mismatch

Register Breakdown#

The general-purpose registers can be broken into smaller parts for byte-level manipulation:

NameSizeDescription
EAX32 bitsFull register
AX16 bitsLower half of EAX
AH8 bitsHigh byte of AX (bits 8–15)
AL8 bitsLow 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 into BL
  • Set BH to 0x42

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 into AH
  • Copy AH into AL (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, ... or mov 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, ... or xchg
  • Do not use rol, ror, shl, or shr
  • 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, ... or mov ax, ...
  • Do not use arithmetic or logical operations (add, or, etc.)
  • Carefully place each byte into the correct part of EAX using mov to 8-bit registers
MOV Instructions
https://frqblog.vercel.app/posts/mov-instruction/
Author
frqblog
Published at
2025-07-26
License
CC BY-NC-SA 4.0