Flashcard Deck · 20 cards · Public

Stanford CS107 - Computer Organization & Systems: C Memory & Assembly

Master low-level system execution, x86-64 assembly, C memory layout, pointer arithmetic, and heap allocator design with this high-yield CS107 study deck.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
What are the four primary memory segments in a C program's virtual address space?
Definition
1. Text: Read-only binary instructions (%rip).
2. Data: Global and static variables (initialized and uninitialized bss).
3. Heap: Dynamically allocated memory managed via malloc/free (grows upward to higher addresses).
4. Stack: Function frames, local variables, and saved registers (grows downward to lower addresses).
#2
Term
What sequence of operations occurs during an x86-64 function call?
Definition
1. Caller: Passes first 6 arguments in registers (%rdi, %rsi, %rdx, %rcx, %r8, %r9), pushes extra args onto stack.
2. Caller: Executes call, which pushes return address (%rip) and jumps to target.
3. Callee: Allocates stack space by decrementing %rsp and saves callee-saved registers.
4. Callee: Executes body, sets return value in %rax.
5. Callee: Restores registers, increments %rsp, runs ret (pops return address into %rip).
#3
Term
Which registers are used to pass the first 6 integer or pointer arguments in x86-64 System V AMD64 ABI?
Definition
In order:
1. %rdi (1st argument)
2. %rsi (2nd argument)
3. %rdx (3rd argument)
4. %rcx (4th argument)
5. %r8 (5th argument)
6. %r9 (6th argument)
Any additional arguments (7+) are pushed onto the stack in reverse order.
#4
Term
What is the difference between caller-saved and callee-saved registers in x86-64 assembly?
Definition
  • Caller-saved (%rax, %rdi, %rsi, %rdx, %rcx, %r8–%r11): Callee function may overwrite these registers freely. Caller must push them onto the stack prior to calling if values are needed after the function returns.
  • Callee-saved (%rbx, %rbp, %r12–%r15): Callee must save original values on the stack before modifying them and restore them before returning.
#5
Term
How does leaq differ from movq in x86-64 assembly?
Definition
  • movq Src, Dest: Accesses memory at address specified by Src and copies the stored payload data into Dest.
  • leaq Src, Dest: Calculates the effective memory address specified by Src expression (e.g., 8(%rdi,%rsi,4)) and stores the computed address itself into Dest without performing a memory read. Frequently used for quick arithmetic like .
#6
Term
How is pointer arithmetic evaluated for p + i where p is a pointer of type T*?
Definition
In C, adding integer to pointer scales the offset by the byte size of underlying data type :

For example, if int *p = 0x1000, p + 2 evaluates to .
#7
Term
What is the alignment requirement rule in C structures, and why is padding added?
Definition
Hardware fetches memory efficiently when data of size bytes resides at an address divisible by (e.g., 4-byte int aligned at address ).
C compilers automatically insert padding bytes inside structs so that every field meets its alignment rule, and pads the overall struct size to a multiple of its largest field's alignment requirement.
#8
Term
Why can you not perform pointer arithmetic directly on a void* pointer in standard C?
Definition
A void* is a generic pointer to an unknown byte type, making sizeof(void) undefined in standard C. Because pointer arithmetic requires scaling steps by size , void* must be explicitly cast (e.g., to char* for byte-level offset scaling) before arithmetic operations.
Showing 8 of 20 cards in this deck.
Study All Now

Related Flashcard Sets

Explore similar study materials created by the community

Browse community decks