Integer Arithmetic Instructions
These instructions operate on registers or memory. S,D represent source and destination.[for ldiv, D must be %eax, and cdq must be used before the divide to sign-extend %eax into %edx, which of course changes %edx.] Usually, S is the rhs and D is the lhs.
addl | S,D | D + S → D | ||
subl | S,D | D - S → D | ||
imull | S,D | D * S → D | ||
ldiv | S,D | D / S → D | ||
cmpl | S,D | compare D - S , set condition | ||
andl | S,D | D ∧ S → D | ||
orl | S,D | D ∨ S → D | ||
notl | D | ¬ D → D | ||
negl | D | - D → D | ||
Note that arithmetic can be done directly on memory:
i := i + 1 can be one instruction:
addl $1,-32(%rbp)