CS 208 reference sheet
Assembly Instructions
mov a, b |
Copy from a to b . |
movs a, b |
Copy from a to be with sign extension. Needs two width specifiers. |
movz a, b |
Copy from a to be with zero extension. Needs two width specifiers. |
lea a, b |
Compute address and store in b . Note: the scaling parameter of memory operands can only be 1, 2, 4, or 8. |
push src |
Push src onto the stack and decrement stack pointer. |
pop dst |
Pop from the stack into dst and increment stack pointer. |
call <func> |
Push return address onto stack and jump to a procedure. |
ret |
Pop return address and jump there. |
add a, b |
Add a to b and store in b (and set condition codes). |
sub a, b |
Subtract a from b (compute b - a ) and store in b (and set condition codes). |
imul a, b |
Multiply a and b and store in b (and set condition codes). |
neg a |
Compute -a according to 2's complement and store in a (and set condition codes). |
and a, b |
Bitwise AND of a and b, store in b (and set condition codes). |
or a, b |
Bitwise OR of a and b, store in b (and set condition codes). |
xor a, b |
Bitwise XOR of a and b, store in b (and set condition codes). |
sar a, b |
Shift value of b right (arithmetic) by a bits, store in b (and set condition codes). |
shr a, b |
Shift value of b right (logical) by a bits, store in b (and set condition codes). |
shl a, b |
Shift value of b left by a bits, store in b (and set condition codes). |
sal a, b |
Shift value of b left by a bits, store in b (and set condition codes). |
cmp a, b |
Compare b with a (compute b - a ), set condition codes based on result (result is not stored). |
test a, b |
Bitwise AND of a and b , set condition codes based on result (result is not stored). |
jmp <label> |
Unconditional jump to address. |
jCOND <label> |
Considtion jump based on condition codes . |
setCOND a |
Set byte a to 0 or 1 based on condition codes. |
Operands
Form | Value | Name |
---|---|---|
$NUM |
Literal value of NUM |
Immediate |
%REG |
Value stored in REG |
Register |
NUM |
Value stored at address NUM |
Absolute |
(%REG) |
Value stored at address in REG |
Indirect |
NUM(%REG) |
Value stored at address REG + NUM |
Base + displacement |
(%REG_B, %REG_I) |
Value stored at address REG_B + REG_I |
Indexed |
NUM(%REG_B, %REG_I) |
Value stored at address REG_B + REG_I + NUM |
Indexed |
(, %REG, S) |
Value stored at address REG * S |
Scaled indexed |
NUM(, %REG, S) |
Value stored at address REG * S + NUM |
Scaled indexed |
(%REG_B, REG_I, S) |
Value stored at address REG_B + REG_I * S |
Scaled indexed |
NUM(%REG_B, REG_I, S) |
Value stored at address REG_B + REG_I * S + NUM |
Scaled indexed |
Conditionals
Instruction | (op) s, d |
test a, b |
cmp a, b |
||
---|---|---|---|---|---|
je |
sete |
"Equal" | d (op) s == 0 |
b & a == 0 |
b == a |
jne |
setne |
"Not equal" | d (op) s != 0 |
b & a != 0 |
b != a |
js |
sets |
"Sign" (negative) | d (op) s < 0 |
b & a < 0 |
b - a < 0 |
jns |
setns |
(non-negative) | d (op) s >= 0 |
b & a >= 0 |
b - a >= 0 |
jg |
setg |
"Greater" | d (op) s > 0 |
b & a > 0 |
b > a |
jge |
setge |
"Greater or equal" | d (op) s >= 0 |
b & a >= 0 |
b >= a |
jl |
setl |
"Less" | d (op) s < 0 |
b & a < 0 |
b < a |
jle |
setle |
"Less or equal" | d (op) s <= 0 |
b & a <= 0 |
b <= a |
ja |
seta |
"Above" (unsigned >) | d (op) s > 0U |
b & a > 0U |
b - a > 0U |
jb |
setb |
"Below" (unsigned <) | d (op) s < 0U |
b & a < 0U |
b - a < 0U |
Registers and Sizes
Name | Convention | Lowest 4 bytes | Lowest 2 bytes | Lowest byte |
---|---|---|---|---|
%rax |
Return value | %eax |
%ax |
%al |
%rbx |
%ebx |
%bx |
%bl |
|
%rcx |
Argument #4 | %ecx |
%cx |
%cl |
%rdx |
Argument #3 | %edx |
%dx |
%dl |
%rsi |
Argument #2 | %esi |
%si |
%sil |
%rdi |
Argument #1 | %edi |
%di |
%dil |
%rsp |
Stack pointer | %esp |
%sp |
%spl |
%rbp |
%ebp |
%bp |
%bpl |
|
%r8 |
Argument #5 | %r8d |
%r8w |
%r8b |
%r9 |
Argument #6 | %r9d |
%r9w |
%r9b |
%r10 |
%r10d |
%r10w |
%r10b |
|
%r11 |
%r11d |
%r11w |
%r11b |
|
%r12 |
%r12d |
%r12w |
%r12b |
|
%r13 |
%r13d |
%r13w |
%r13b |
|
%r14 |
%r14d |
%r14w |
%r14b |
|
%r15 |
%r15d |
%r15w |
%r15b |
C type | x86-64 suffix | Size in bytes |
---|---|---|
char |
b |
1 |
short |
w |
2 |
int |
l |
4 |
long |
q |
8 |