1/62
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Procedure
An abstraction mechanism that encapsulates code with a set of parameters and a return value, allowing execution control and data flow to transfer cleanly to another part of the program.
x86-64
An instruction set architecture: the instructions a processor understands, its registers, and the rules for using them. It is the interface between software and hardware.
Also written x64, AMD64, or Intel 64
In stack, Grows toward lower addresses
Every call solves three problems.. 1? 2? 3?
Passing control
Passing Data
Allocating Memory
Register
A small storage location inside the processor itself, usually 64 bits(8 bytes). A processor has about sixteen, and reading one is far faster than reading main memory.
%
Punctuation only. It tells the assembler that a word is a register name
“rax” , etc.
Run-Time Stack
A contiguous region of memory organized as a stack that manages procedure calls, parameter passing, return address, and local storage.
If P calls Q, __ must finish before __continues
Q must finish before P continues. The most recent call is always the first to complete. — LIFO rule
Stack Frame
The private region of the stack belonging to one invocation of one function.
A portion of the run-time stack allocated specifically for a single procedure execution, bounded by the stack pointer %rsp (and option a frame pointer %rbp )
Stack Pointer (%rsp)
A dedicated x86 - 64 register that holds the memory address of the top of the stack.
Control Transfer
The mechanism by which execution branches to the beginning og a called procedure using call and returns to the calling code using ret.
Return Address
The address iof the instruction immediatley following a call instruction, which is pushed ontot he stack so the CPU knows where to resme execution upon returning.
Calling conventions registers
Registers (%rax , %rdi, %rsi, %rdx, %rcx, %r8 - %r11 ) whose conents may be overwritten by a called procedure
Callee-Saved Registers
Registers (%rbx, %rbp, %r12, %r15 ) whose contents must be preserved across procedure calls
Array
A contiguous region of memory storing a sequence of homogeneous elements, accessed using zero-based indexing.P
Pointer arithmetic
An operation where adding or subtracting an integer i to a pointer automatically scales i by size Iin bytes) or the underlying data type ( Address = Xa + L * i)N
Nested Array (Multidimensional Array)
An array whose elements are themselves arrays major order as single contiguous memory blow
Row-Major Order
A memory layout strategy where multi-dimensional array elements are stored row by row in contiguous memory locations.
Fixed-size array
An array whose dimensions are known and fixed at compile time, allowing the compiler to optimize indexing computations into direct address calculations.
Variable-size array (VLA)
An array whose dimensions are determined dynamically at run time, requiring extra arithmetic (or scaling registers) to calculate element address.
Structure (struct)
A C data structure that groups elements of potentially different data types into a single contiguous block of memory, storing fields at fixed byte offsets relative to the start of the structure.U
Union (union)
A C data structure that allows a single block of memory to be referenced using multiple different data types; its total size equals the size of its largest member, and all share the same starting address offset (0)
Data Alignment
A hardware placement requirement where object memory address must be multiple of a specific value K (typically 2, 4, or 8) , ensuring efficient memory bus transfers and preventing performance penalties or bus errors.P
Padding
Unused bytes inserted by the compiler between structure fields or at the end of a structure to satisfy data alignment constraints.
Call
Pushes the return address - the address of the instruction immediatley after the call - onto the stack, so %rsp decreases by 8, the size of one address. Then sets %rip to the address of the called function.
ret
Pops the return address of the stack into %rip, so rsp increases by 8, and execution resumes in the caller at exactly the instruction after the call.
Passing data : arguments and return values
They are assigned in a fixed order: first argument in %rdi, second in %rsi, and so on. Arguments seven and beyond go on the stack, padded to a multiple of 8 bytes, just above the return address: arg 6 16(%rsp) argument 8 8(%rsp) argument 7 0(%rsp) return address The return value is always placed in %rax.

A functions needs space only in three situations 1?2?3?
There are more local values than available registers.
The address operator & is applied to a loccal variable, so it must occupy a real memory address.
The variable is an arrray or a structure, which cannot fit in a single register.
How does x86-64 prevent recursive function calls from overwriting earlier calls' local variables?
Each function invocation receives its own separate stack frame allocated at a lower memory address, ensuring every call maintains distinct memory for its parameters and local variables.
In what order are stack frames allocated and deallocated during a recursive call sequence?
Stack frames accumulate (grow downward) as recursion descends toward the base case, and are deallocated in reverse order (LIFO — Last In, First Out) as each call returns.
Complete Sequence Order (Function or procedure call in C/Assembly)
Caller prepares
Call executes
Callee executes
ret executes
Push
The call instruction pushes the return address onto the stack.
Jump
The CPU jumps to the called function’s code C
Compute
The function executes its work/math on theCPU.
Pop
The ret instructions pops the return address of the stack
Jump
The CPU jumps back to the caller’s code to resume execution.
Heterogeneous
Made of different types. An array is homogeneoues - every element has the same type.
Field
One named value stored inside a structure or union, such as grade or score.
Offset
The distance in bytes from the start of the structure to the beginning of a field.A
Alignment
The rule that a value must begin at an address that is a multiple of its own size.
Pointer Size on 64-bit Architecture
Always 8 bytes
char* , int* , struct *
&x
Address-of-operator(produces memory address of x)
*p
Dereference operator(access “the value stored at that address”)
Pointer Arithmetic Scaling
Adding 1 (p+1) advances the pointer address by sizeof(*p) bytes. NOT 1 byte
Pass by value in C
Passes all function parameters by value
void *
A pointer type with no associated element size.
Cannot be dereferenced or used directly in arithmetic without explicit casting.
argc
Argument count
argv[0]
Holds the name of the exacutable program
sizeof
A compile-time operator that returns the total size in bytes of a type or variable, including any padding bytes added for alignment
typedef
Creates a new alias/name for an existing data type. It creates no new data type and does not change memory layout.
break main / break file.c:20
Set a breakpoint at a function or a line.
run
Start the program
continue
resume after a stop
next
next runs the next line over any call
step
step goes into the call.
print x
Shows a value
print &x
show its address.
print sizeof(struct Employee)
Confirm a struct size, padding included.
print &e.score
Confirm a field offset — subtract &e from it.
x/12xb &e
Examine 12 bytes in hex starting at the address of e — this is how you see padding.
info locals
Show local variables
info registers
show register contents including %rsp and %rip.
backtrace (bt)
Show the chain of stack frames

finish
Run until the current function returns, and show its return value.