Computer System Ch.3

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/62

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:02 AM on 9/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

63 Terms

1
New cards

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.

2
New cards

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


3
New cards

Every call solves three problems.. 1? 2? 3?

  1. Passing control

  2. Passing Data

  3. Allocating Memory


4
New cards

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.

5
New cards

%

Punctuation only. It tells the assembler that a word is a register name

  • “rax” , etc.


6
New cards

Run-Time Stack

A contiguous region of memory organized as a stack that manages procedure calls, parameter passing, return address, and local storage.

7
New cards

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

8
New cards

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 )


9
New cards

Stack Pointer (%rsp)

A dedicated x86 - 64 register that holds the memory address of the top of the stack.

10
New cards

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.

11
New cards

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.

12
New cards

Calling conventions registers

Registers (%rax , %rdi, %rsi, %rdx, %rcx, %r8 - %r11 ) whose conents may be overwritten by a called procedure

13
New cards

Callee-Saved Registers

Registers (%rbx, %rbp, %r12, %r15 ) whose contents must be preserved across procedure calls

14
New cards

Array

A contiguous region of memory storing a sequence of homogeneous elements, accessed using zero-based indexing.P

15
New cards

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

16
New cards

Nested Array (Multidimensional Array)

An array whose elements are themselves arrays major order as single contiguous memory blow

17
New cards

Row-Major Order

A memory layout strategy where multi-dimensional array elements are stored row by row in contiguous memory locations.

18
New cards

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.

19
New cards

Variable-size array (VLA)

An array whose dimensions are determined dynamically at run time, requiring extra arithmetic (or scaling registers) to calculate element address.

20
New cards

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

21
New cards

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)

22
New cards

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

23
New cards

Padding

Unused bytes inserted by the compiler between structure fields or at the end of a structure to satisfy data alignment constraints.

24
New cards

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.

25
New cards

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.

26
New cards

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.

<p>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 <code>%rax</code>.</p>
27
New cards

A functions needs space only in three situations 1?2?3?

  1. There are more local values than available registers.

  2. The address operator & is applied to a loccal variable, so it must occupy a real memory address.

  3. The variable is an arrray or a structure, which cannot fit in a single register.


28
New cards

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.

29
New cards

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.

30
New cards

Complete Sequence Order (Function or procedure call in C/Assembly)

  1. Caller prepares

  2. Call executes

  3. Callee executes

  4. ret executes


31
New cards

Push

The call instruction pushes the return address onto the stack.

32
New cards

Jump

The CPU jumps to the called function’s code C

33
New cards

Compute

The function executes its work/math on theCPU.

34
New cards

Pop

The ret instructions pops the return address of the stack

35
New cards

Jump

The CPU jumps back to the caller’s code to resume execution.

36
New cards

Heterogeneous

Made of different types. An array is homogeneoues - every element has the same type.

37
New cards

Field

One named value stored inside a structure or union, such as grade or score.

38
New cards

Offset

The distance in bytes from the start of the structure to the beginning of a field.A

39
New cards

Alignment

The rule that a value must begin at an address that is a multiple of its own size.

40
New cards

Pointer Size on 64-bit Architecture

Always 8 bytes

  • char* , int* , struct *


41
New cards

&x

Address-of-operator(produces memory address of x)

42
New cards

*p

Dereference operator(access “the value stored at that address”)

43
New cards

Pointer Arithmetic Scaling

Adding 1 (p+1) advances the pointer address by sizeof(*p) bytes. NOT 1 byte

44
New cards

Pass by value in C

Passes all function parameters by value

45
New cards

void *

A pointer type with no associated element size.

  • Cannot be dereferenced or used directly in arithmetic without explicit casting.



46
New cards

argc


Argument count

47
New cards

argv[0]

Holds the name of the exacutable program

48
New cards

sizeof

A compile-time operator that returns the total size in bytes of a type or variable, including any padding bytes added for alignment

49
New cards

typedef

Creates a new alias/name for an existing data type. It creates no new data type and does not change memory layout.

50
New cards

break main / break file.c:20

Set a breakpoint at a function or a line.

51
New cards

run

Start the program

52
New cards

continue

resume after a stop

53
New cards

next

next runs the next line over any call

54
New cards

step

step goes into the call.

55
New cards

print x

Shows a value

56
New cards

print &x

show its address.

57
New cards

print sizeof(struct Employee)

Confirm a struct size, padding included.

58
New cards

print &e.score

Confirm a field offset — subtract &e from it.

59
New cards

x/12xb &e

Examine 12 bytes in hex starting at the address of e — this is how you see padding.

60
New cards

info locals

Show local variables

61
New cards

info registers

show register contents including %rsp and %rip.

62
New cards

backtrace (bt)

Show the chain of stack frames

<p>Show the chain of stack frames </p>
63
New cards

finish

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