← Back to Articles

The MOV Instruction

Introduction to MOV

The MOV (move) instruction is the most fundamental instruction in assembly language. Despite its name, MOV doesn't actually "move" data - it copies data from one location to another, leaving the original intact.

MOV is used for:

  • Loading immediate values into registers
  • Copying data between registers
  • Initializing variables
  • Setting up calculations

MOV Syntax

The basic syntax of MOV is:

MOV destination, source

Where:

  • destination is a register that will receive the value
  • source is either an immediate value or another register

MOV with Immediate Values

Immediate values are constants prefixed with #:

MOV R0, #42      // Load 42 into R0
MOV R1, #0       // Load 0 into R1
MOV R2, #-10     // Load -10 into R2
MOV R3, #1000    // Load 1000 into R3

This is the most common use of MOV - initializing registers with known values.

MOV Between Registers

You can also copy values from one register to another:

MOV R0, #100     // R0 = 100
MOV R1, R0       // R1 = R0 (now R1 = 100 too)
MOV R2, R1       // R2 = R1 (now R2 = 100 too)

Note that the source register (R0 in the second line) is not changed - its value is copied to the destination.

Common MOV Patterns

Clearing a Register

MOV R0, #0       // Set R0 to zero

Initializing Multiple Registers

MOV R0, #10      // Initialize R0
MOV R1, #20      // Initialize R1
MOV R2, #30      // Initialize R2

Preserving Values

MOV R5, R0       // Save R0's value in R5
// ... do calculations with R0 ...
MOV R0, R5       // Restore R0's original value

Practical Examples

Example 1: Swapping Register Values

// Swap values in R0 and R1 using R2 as temporary
MOV R0, #5       // R0 = 5
MOV R1, #10      // R1 = 10
MOV R2, R0       // R2 = 5 (save R0)
MOV R0, R1       // R0 = 10 (copy R1 to R0)
MOV R1, R2       // R1 = 5 (copy saved value to R1)
// Now R0 = 10 and R1 = 5

Example 2: Setting Up a Calculation

// Calculate: (5 + 3) * 2
MOV R0, #5       // First operand
MOV R1, #3       // Second operand
ADD R2, R0, R1   // R2 = 5 + 3 = 8
MOV R3, #2       // Multiplier
MUL R4, R2, R3   // R4 = 8 * 2 = 16

MOV Limitations

Warning: MOV cannot directly load from or store to memory. For memory operations, use LDR (load) and STR (store) instructions, which we'll cover in a later article.

What MOV CAN'T do:

  • MOV R0, 100 (missing #) - must use #100 for immediate values
  • MOV #5, R0 - destination must be a register
  • MOV R0, R1, R2 - only two operands allowed

Performance Notes

MOV is one of the fastest instructions because:

  • It operates entirely within the CPU
  • No memory access required
  • Single clock cycle in most processors

Use MOV liberally - it's cheap and essential for nearly every assembly program.

Exercise

Try writing a program that:

  1. Loads the value 7 into R0
  2. Copies R0 to R1
  3. Loads the value 3 into R2
  4. Copies R2 to R3
Show Solution
MOV R0, #7
MOV R1, R0
MOV R2, #3
MOV R3, R2
HALT