Title: CSE 351 23au / LS11 Procedures I

Q: Local variables and procedure context are held in the ___
A: stack

Q: In the memory address space, does the stack reside at the highest or lowest usable memory addresses?
A: The highest

Q: True or false: The stack grows upwards towards higher addresses
A: False, the stack grows towards lower addresses (and the heap) where the “top” of the stack is the lowest address

Q: Is the stack managed automatically?
A: Yes, managed by the compiler and assembly instructions

Q: Variables allocated with “new” or “malloc” are held in the ___
A: heap

Q: True or false: The heap grows upwards towards higher addresses
A: True! It also grows towards the stack

Q: The heap is managed dynamically by the ___ and ___
A: Programmer and memory allocator

Q: Static variables including globals are held in the ___ segment
A: static data

Q: The static data section has a ___ size (managed statically), but the data within can change
A: predetermined/fixed

Q: Large constants including string literals and constants are stored in the ___ segment
A: literals

Q: Because the literals section contains large constants and literals (immutable values), it is ___ managed
A: statically

Q: Machine code is stored in the ___ segment
A: instructions

Q: In the memory address space, do program instructions reside at the highest or lowest usable memory addresses?
A: Lowest

Q: The address of the top of the stack is stored in the ___
A: stack pointer (%rsp)

Q: In what register is the stack pointer stored?
A: %rsp

Q: True or false: Addresses < Reg[rsp] (addresses lower than what’s stored in %rsp) are not considered part of the stack.
A: True, the stack grows downwards (towards lower addresses), therefore %rsp will contain the lowest address in the stack, which is the top of the stack
Any addresses less than what is stored in %rsp are not included in the stack

Q: When accessing memory that doesn’t exist, invalid addresses, or protected memory, you will run into ___
A: segmentation faults (seg faults)

Q: The push src instruction will ___ %rsp and then ___ the data from the source into the newly allocated space
A: decrement, copy

Q: The pop dst instruction will ___ the data from %rsp into the destination operand and ___ %rsp to deallocate that space
A: copy, increment

Q: In one instance of a call instruction, the procedure doing the calling is the __
A: caller

Q: In one instance of a call instruction, the procedure being called is the ___
A: callee

Q: When we are passing control from one procedure to another, why is having a return address important?
A: A procedure can be called from multiple places in code and we need a way to indicate how to return to the caller

Q: True or false: The return address of the procedure is the address of its original call instruction, not the address of its caller’s next instruction
A: False, if every procedure returned to the address of its original call, we’d be stuck an in infinite loop. The return address is the address of the caller’s next instruction to execute.

Q: To pass control to another procedure, the call label instruction will automatically ___ the return address onto the stack and update ___ to the address of the specified label
A: push, %rip

Q: When a procedure wants to return control, the ret instruction will automatically ___ the return address off the stack and update ___ to the popped address.
A: pop, %rip

Q: Which register tells us which instruction to execute next?
A: %rip

Q: True or false: In x86-64, only a single value can be passed back in %rax, either directly as a value or via a pointer
A: True

Q: What registers match the mnemonic: Diane’s Silk Dress Cost $8 9?
A: %rdi
%rsi
%rdx
%rcx
%r8
%r9

Q: When passing data into a procedure, all additional arguments must be placed on the stack in ___ order
A: reverse