1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Define a subroutine.
A subroutine is a reusable sequence of instructions that performs a specific task and can be called from different parts of a program.
Difference between caller and callee.
caller=program that contains call instruction / callee=subroutine that contains the return instruction
Compare JSR and JSRR.
JSR uses PC-relative addressing to jump to a subroutine, while JSRR uses a base register to determine the target address.
Both instructions store the return address in R7 so the program can return after the subroutine finishes.
HOW JSR / JSRR WORK
Both:
save return address → R7
jump to subroutine
JSR:
uses offset from PC
JSRR:
uses register value
What is RET and why is it “fake”?
RET is a pseudo-instruction that returns from a subroutine by jumping to the address stored in R7. It is considered “fake” because it is actually translated into JMP R7.
Define and contrast caller-save and callee-save
caller = program saves & restores registers
callee = subroutine saves & restores the registers
difference = who saves register
What is a stack?
a data structure that follows Last-In, First-Out (LIFO), meaning the last value added is the first one removed.
What is the stack pointer?
The stack pointer is a register (R6 in LC-3) that holds the address of the top of the stack and is used to manage push and pop operations.
Where is the stack pointer stored?
The stack pointer is stored in register R6.
Why doesn’t the stack physically move?
The stack does not physically move because only the stack pointer changes. This is efficient because it avoids copying data and allows fast push and pop operations.
How does push work?
decreases the stack pointer and stores a value at the new top of the stack
How does pop work?
Pop retrieves the value at the top of the stack and then increases the stack pointer.
Define stack overflow and underflow.
overflow: stack pointer so small it’s now in same range as memory or data of the program
underflow: when the stack pointer is larger than the memory location where the stack starts
How are strings stored?
as ASCII characters in consecutive memory locations and are terminated by a null character (x0000).