Arithmetic Instructions: ADD, SUB, MUL, DIV
You'll learn how assembly language performs basic math operations directly on CPU registers and memory locations.
The Core Idea
Arithmetic instructions are the fundamental commands that let the CPU perform mathematical calculations. Just as you might write x = a + b in a high-level language, assembly provides specific instructions like ADD, SUB, MUL, and DIV to accomplish the same operations—but you're working directly with registers and memory addresses instead of variable names.
How Arithmetic Instructions Work
Think of these instructions as direct commands to the ALU (Arithmetic Logic Unit) you learned about earlier. Each instruction specifies:
- What operation to perform (add, subtract, multiply, divide)
- Where the operands are (which registers or memory locations)
- Where to store the result (typically one of the operand registers)
Common Syntax Pattern
Most assembly languages follow patterns like:
ADD destination, source ; destination = destination + source
SUB destination, source ; destination = destination - source
MUL source ; multiply accumulator by source
DIV source ; divide accumulator by source
For example, if register AX contains 10 and register BX contains 3:
ADD AX, BX→ AX becomes 13SUB AX, BX→ AX becomes 7MUL BX→ AX becomes 30DIV BX→ AX becomes 3 (with remainder handled separately)
Why This Matters
These instructions form the building blocks for all computation. Every complex calculation ultimately breaks down into sequences of these basic operations executed at hardware speed.
Key Takeaway: Assembly arithmetic instructions (ADD, SUB, MUL, DIV) directly manipulate register and memory values, giving programmers low-level control over mathematical operations performed by the CPU's ALU.