Some Intel Assembler Instructions
The following is a subset of
gcc-supported
Intel instructions. There is a
larger list on page 388 of our text.
If an instruction below ends with a *, then the true instruction name ends
with a l, w, or b depending on the size of its operands. Here's the rule:
- "long" - 4 byte operands, instruction ends in 'l'
- "word" - 2 byte operands, instruction ends in 'w'
- "byte" - 1 byte operands, instruction ends in 'b'
1. Data movement instructions
Instructions that shuffle data around.
| Instruction |
Description |
Example(s) |
| mov* src, dest |
Move a value from memory to/from a register
dest = src |
movl $17, %eax |
| xchg* src, dest |
Exchange values
dest = src
src = dest |
|
| push* src |
Push a value on the stack
mem[stack] = src
decrease %esp |
pushl %edx |
| pop* dest |
Pop a value from the stack
dest = mem[stack]
increase %esp |
pop %ebp |
2. Arithmetic instructions
For the instructions below, * can be substituted with l, w, or b depending on
the size of your operands.
| Instruction |
Description |
Example(s) |
| add* src, dest |
Add
dest = dest + src |
addl $4, %esp |
| sub* src, dest |
Subtract
dest = dest - src |
subl $8, %esp |
| imul* src, dest |
Integer multiply
dest = dest * src |
|
| idiv* src, dest |
Integer division
dest = dest / src |
|
| inc* dest |
Increment
dest++ |
|
| dec* dest |
Decrement
dest-- |
|
3. Logical/Boolean instructions
These instructions perform a bitwise Boolean operations.
| Instruction |
Description |
Example(s) |
| and*
src, dest |
Boolean and
dest = dest AND src |
|
| or*
src, dest |
Boolean or
dest = dest OR src |
|
| xor*
src, dest |
Boolean exclusive-or
dest = dest XOR src |
|
| not*
dest |
Boolean inversion
dest = NOT dest |
|
4. Comparison and Jumps
These instructions simulate subtracting the source from the destination and
set the flags in the eflags register.
| Instruction |
Description |
Example(s) |
| cmp* src, dest |
Compare two values
dest - src ==> set eflags reg |
|
| jmp addr |
Unconditionally jump to an address |
|
| jz addr |
Jump if eflags is "zero" |
|
| jnz addr |
Jump if eflags is "not zero" |
|
| je addr |
Jump is eflags is "equal" |
|
| jne addr |
Jump if eflags is "not equal" |
|
| jl addr |
Jump if eflags is "less than" |
|
| jle addr |
Jump if eflags is "less than or equal" |
|
| jg addr |
Jump if eflags is "greater than" |
|
| jge addr |
Jump if eflags is "greater than or equal" |
|
5. Function-related instructions
Instructions related to handling function calls.
| Instruction |
Description |
Example(s) |
| call func |
Call function; pushes return address onto stack
|
call _printf |
| ret |
Return from function; pops the return address that must be
on the stack |
ret |
| leave |
Prepares for ret instruction; equivalent to
movl%ebp, %esp
popl %ebp |
leave
ret |
|