CS 208 Quick Reference

This quick reference guide is based on one created by Aaron Bauer and adapted by Jeff Ondich.

Bits and binary

Helpful conversions: Bits and binary

Assembly instructions

Instruction
Description
mov a, b Copy from a to b.
movs a, b Copy from a to b with sign extension. Needs two width specifiers.
movz a, b Copy from a to b 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 the stack pointer.
pop dst Pop from the stack into dst and increment the stack pointer.
call <func> Push the return address on to the stack and jump to the first instruction of procedure <func>.
ret Pop the return address from the stack and jump to that address.
add a, b Store b+a in b. Set condition codes.
sub a, b Store b-a in b. Set condition codes.
imul a, b Store b*a in b. Set condition codes.
neg a Store -a (according to 2’s complement) in a. Set condition codes.
and a, b Store bitwise-AND of a and b in b. Set condition codes.
or a, b Store bitwise-OR of a and b in b. Set condition codes.
xor a, b Store bitwise-XOR of a and b in b. Set condition codes.
sar a, b Shift value of b right (arithmetic) by a bits and store in b. Set condition codes.
shr a, b Shift value of b right (logical) by a bits and store in b. Set condition codes.
sal a, b Shift value of b left by a bits and store in b. Set condition codes.
shl a, b Same as sal.
cmp a, b Compare b:a. Set condition codes based on b-a, but do not store b-a anywhere.
test a, b Compute bitwise-AND of a and b, but do not store a&b anywhere. Set condition codes based on a&b.
jmp <label> Unconditional jump to address <label>.
jCOND <label> Conditional jump based on condition codes.
setCOND a Set byte a to 0 or 1 based on condition codes.

Conditionals

Instruction
Meaning
(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
%rdx argument #3 %edx %dx %dl
%rcx argument #4 %ecx %cx %cl
%rdi argument #1 %edi %di %dil
%rsi argument #2 %esi %si %sil
%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