You are on page 1of 1

● x86 Assembly Language (How the compiler interprets code)

○ Registers (different from memory, faster to access): %rax, $rbx, rcx… etc
■ Have different names depending on which bytes ($eax = last 4 of $rax)
○ Instructions: Transfers, math, or control flows
■ Ex: mov source, destination, add source, destination, jump address
■ Special Cases: D(Rb, Rbi) = Rb, + Rbi + D, (Rb, Rbi, S) = Rb + Rbi + S
■ Parentheses still work as “Address of” and lea just does math
○ Condition codes: CF, ZF, SF, OF
■ Unsigned overflow, equals 0, less than 0, signed overflow
■ Set implicitly and explicitly by arithmetic and compare operations
○ Also have statements for Conditionals, Loops, Switches
● Stack
○ %rsp is the stack pointer, “grows down” and $rax is the return value
○ Caller vs. Callee (Must know args and return address vs. return value)
■ Caller must save valuable information in caller saved registers and callee
must save relevant information before usage in callee saved registers
■ Analogy: Caller is parents leaving house to kids, kids are callee who want
to party. Parents hide valuables before they leave (Caller saved) and kids
move stuff into shed before house is trashed (callee saved) then moves it
back and parents come home and move their stuff back
○ $rdi, $rsi, $rdx, $rcx, $r8, $r9 first 6 parameters the allocate more on stack
○ Stack frames provide state for single procedure instantiation
● Executables
○ C program > Assembly > Object program > Binary program
■ Different compiler flags can get your different formats/files
■ Ex: Object Table & Relocation Table
● Arrays
○ One dimensional T A[N] size N type T (identified by array address)
■ Array access relies on address, index, and scale
■ No bounds! Also, arrays might not be stored successively
○ Multi dimensional TA[R][C] type T of row R and column C
■ Each row is laid out one after another in memory (guaranteed)
■ Must take into account scale when accessing, as well as row and column
● Row # * row length + column# * scale
○ Multi level - Multi dimensional but not successively stored
■ To access must first access pointer to proper row, then to proper index
● Structs
○ A group of variables, can be different data types
○ Declare at the top as a global variable, use pointer
○ Continuously allocated piece of memory of different types
○ Fields are ordered by declaration, declare bigger data types before smaller ones
○ Data types must start at an address that’s a multiple of their size, buffers fill out
remaining space inside and out

You might also like