Instruction Set Basics: MOV, Arithmetic & Logic
Instruction Set Basics: MOV, Arithmetic & Logic
This page introduces the concept of the CPU instruction set, the fundamental operations available to all programs, and the most common x86-64 instructions for data movement, arithmetic, and logic.
What is an instruction set
A CPU executes binary-encoded instructions stored in memory. Each instruction defines a specific operation that the processor can perform directly. The complete list of supported instructions is called the **Instruction Set Architecture (ISA)**.
On x86-64 CPUs, there are hundreds of instructions, covering:
- Data movement
- Arithmetic and logic
- Conditional execution and branching
- Function and system calls
Every instruction has:
- An operation code (opcode)
- One or more operands (registers, memory addresses, or constants)
Example (human-readable form):
MOV RAX, RBX
This means “copy the value from RBX into RAX.”
Data movement instructions
Moving data is one of the most frequent operations in any program. It allows transferring information between memory, registers, and I/O ports.
Common forms:
- Register ← Register
- Register ← Memory
- Memory ← Register
- Register ← Immediate value
Example:
MOV RAX, 5 ; Load immediate value 5 into RAX
MOV RBX, RAX ; Copy RAX into RBX
MOV [0x600000], RAX ; Store RAX to memory address 0x600000
MOV RCX, [0x600000] ; Load from memory into RCX
Arithmetic instructions
The Arithmetic Logic Unit (ALU) performs basic arithmetic operations. The following instructions work on integer data:
Instruction | Description
| ------------
ADD | Add two values SUB | Subtract one value from another INC | Increment by 1 DEC | Decrement by 1 MUL | Multiply unsigned values IMUL | Multiply signed values DIV | Divide unsigned values IDIV | Divide signed values
Example:
MOV RAX, 10
ADD RAX, 20 ; RAX = 30
SUB RAX, 5 ; RAX = 25
INC RAX ; RAX = 26
Logical instructions
Logical operations manipulate bits directly. They are used for testing, masking, and controlling specific flags.
Instruction | Description
| ------------
AND | Bitwise AND OR | Bitwise OR XOR | Bitwise exclusive OR NOT | Bitwise inversion SHL | Shift bits left SHR | Shift bits right
Example:
MOV AL, 0b11001010
AND AL, 0b11110000 ; Result: 0b11000000
OR AL, 0b00001111 ; Result: 0b11001111
XOR AL, 0b11111111 ; Result: 0b00110000
Why arithmetic and logic matter
Arithmetic and logic form the basis for all computation. By combining these with memory access and branching, a CPU can implement any algorithm—from simple addition to complex data structures.