Registers

Suffix for Moving Data:

b - byte - 8bit - associated with char
w - word - 16bit - associated with short
l - long - 32bit - associated with int
q - quad - 64 bit - associated with long, double, pointer

Types of Registers

<aside> 💡 We always have to push RBX when it is in use

</aside>

Untitled

%rdi, %rsi, %rdx, %rcx, %r8, %r9 inputs in orders
%r10, %r11 //caller saved (values might be different after call
%RSP, rbx, %rbp, %r12, %r13, %r14, %r15 // values same after call

NONE ARE GUARENTEED DIFFERENT VALUE BEFORE AFTER CALL

Different Operations

## Two Operand Instructions

addq  src,dest -> dest = dest+src
subq  src,dest -> dest = dest-src
imulq src,dest -> dest = dest*src
salq  src,dest -> dest = dest << src
sarq  src,dest -> dest = dest >> src (arithmetic) (not always accurate)
shrq  src,dest -> dest = dest >> src (logical shift right)
xorq  src,dest -> dest = dest^src
andq  src,dest -> dest = dest&src
orq   src,dest -> dest = dest | src

// When dividing, the issue arises with rounding towards zero and we
// can add a smaller number to bias the dividend towards zero

## One Operand Instructions
incq dest dest = dest+1
decq dest dest = dest-1
negq dest dest= -dest
notq dest dest= ~dest

Memory Addressing Modes

<aside> 💡 The general form is as follows: D(Rb, Ri, S)

Untitled

Comparisons

Compare Instruction

cmpq src, src2
cmpq b, a 
// is like computing a with b without setting the destination
// generally followed with some sort of jump statement, or set statement
// JGA if A is greater than B, jump

Test Instruction

testq src2, src1
testq b,a is like computing a&b without setting the destination

if (x == y) ~ example of when testq is used