NASM Coding: Common Instructions

Here are many of the instructions that we will used in our NASM programs, and their description:

Instruction Description Operands
add x, y
x += y;
Numbers as registers or variables (
y
can also be a literal)
and x, y
x &= y;
Registers or variables (
y
can be a literal); they will be bitwise ANDed
cmp x, y
Is
x == y
?
Registers, variables, or literals; the OS sets the sign, zero, carry, and overflow flags
dec x
x -= 1;
Register or variable
div x
rax:rdx /= x;
Register, variable, or literal; unsigned integer division; quotient is put in
rax
and remainder in
rdx
by the OS
idiv x
rax:rdx /= x;
Register, variable, or literal; signed integer division; quotient is put in
rax
and remainder in
rdx
by the OS
imul x
rax:rdx = x * rax;
Register, variable, or literal; signed multiplication
imul x, y
x *= y;
x
is a register and
y
is a register or variable; signed multiplication
imul x, y, z
x = y * z;
x
is a register;
y
is a register or variable;
z
is a numeric literal (e.g.,
5
); signed multiplication