Meeting Summary: CS 315-02 Lecture/Lab (Fall 2025)¶
- Date: Sep 11, 2025, 02:51 PM Pacific Time (US and Canada)
- Zoom ID: 868 6589 0521
Quick Recap¶
- The instructor (Greg) emphasized learning through hands-on problem solving, especially around function calls and register management.
- The class reviewed stack allocation, saving/restoring registers, and the role of caller- and callee-saved registers in function calls.
- Examples covered how the return address (RA) changes during calls, when and how to save registers, and how to write simple functions that don’t need stack frames.
- The session introduced recursion, its role across languages, and how to translate recursive logic into assembly and iterative C.
- Upcoming topics include more complex conditional logic in assembly and support for accessing Zoom recordings.
Action Items¶
- Instructor:
- Share last fall’s midterm as a reference.
- Provide practice problems by the end of the week.
- Demonstrate a version of the “Add for F” program using S registers.
-
Explore using ChatGPT in study mode with Project 2 to support concept learning.
-
Students:
- Complete the practice problems by next week.
- Practice problem-solving skills to prepare for the exam.
- Ensure understanding of assembly concepts used in the projects.
- Follow RISC‑V calling conventions, especially around caller‑saved and callee‑saved registers.
Topics Covered¶
Learning Through Struggle in Software¶
- The instructor emphasized that durable learning comes from struggle and hands-on practice rather than copying answers from AI tools.
- Students were encouraged to invest time in understanding concepts deeply, ask for help when needed, and trust that projects are designed to prepare them for exams and real-world work.
- The evolving role of developers in the age of AI was discussed, highlighting the value of expertise and problem-solving.
Calling Conventions: Caller-Saved vs. Callee-Saved Registers¶
- RA (return address) is treated as caller-saved: if the caller needs RA preserved across a call, it must save it.
- The distinction between register classes was reviewed:
- Caller-saved (volatile): typically argument registers (a0–a7), temporaries (t0–t6), and ra.
- Callee-saved (non-volatile): s0–s11 (saved registers) and other non-volatile state. If a callee uses these, it must save/restore them.
- Guidance:
- Avoid redundant save/restore inside loops.
- Simple leaf functions (no stack usage and no calls to other functions) do not require stack setup/teardown.
Stack Allocation and Register Saving¶
- Function calls change the RA; saving RA and any needed registers is necessary to return correctly.
- All addresses on the target architecture are 64-bit (8 bytes).
- Stack frames must be aligned to a multiple of 16 bytes.
- Example scenarios showed allocating 32 bytes to save multiple registers and maintain alignment.
Examples and Code Quality¶
- The add4f function was demonstrated using:
- Caller-saved registers.
- S (saved) registers with proper callee-saved handling.
- Students were advised to follow the original C logic closely when writing assembly.
- Even if incorrect register choices “work,” they can reduce code quality and violate convention.
Recursion: Concepts and Design¶
- Recursion was discussed in the context of:
- Traversing trees and graphs.
- Functional programming languages where recursion replaces loops.
- Two C-style patterns were compared:
- Direct recursive returns.
- Using intermediate variables to store return values, which often simplifies translation to assembly.
- Single return points can be easier to debug, though multiple returns are common in practice.
Converting Recursive to Iterative Code¶
- A factorial example illustrated how to convert recursion to iteration:
- Understand the recursive logic first.
- Identify where values must persist across calls.
- Use intermediate variables to hold return values.
- Determine which registers to save, set up arguments, and preserve needed values after calls.
- This example required only one additional stack slot beyond the usual frame.
Understanding Recursive Calls (with GDB)¶
- The instructor stepped through a recursive factorial in GDB to show:
- How RA and arguments are saved on the stack during each call.
- How values are restored during unwinding.
- How the stack evolves across multiple recursive levels and returns.
Recursion and Assembly Language; Complex Conditions¶
- Recursion was compared across Java and Python, then grounded in assembly translation.
- The class examined building complex conditions in assembly using multiple branches to achieve high-level logic.
- An exercise was assigned, with reminders about office hours and upcoming deadlines; students were encouraged to start early and ask questions via Campuswire.
Exam Accommodation and Zoom Support¶
- A student requested an exam accommodation due to a family event and travel; the instructor is considering options.
- For Zoom recordings, students should use the SSO login button to authenticate properly.