Skip to content

CS 631-01 Systems Foundations — Meeting Summary

  • Date: Mar 05, 2026
  • Time: 08:15 AM Pacific Time (US and Canada)
  • Meeting ID: 870 0988 0761

Quick Recap

The session focused on function calls, calling conventions, and recursion in RISC-V assembly. Key topics included: - How PC (program counter) and RA (return address) are used during calls and returns - The distinction between caller-saved and callee-saved registers - Handling multiple function calls and recursion - Passing arguments via registers and the stack (especially for 9+ arguments) - Stepping through recursive functions in GDB - The importance of following RISC-V calling conventions for correctness and interoperability

Next Steps

  • Greg: Fix the hard-coded 30-second timeout in the autograder for both Python and Rust implementations before auto-grading.
  • Greg: Post the next lab (covering larger functions, calling conventions, and recursion) by this afternoon.
  • Greg: Include the recursion problem in the next lab and release it by this afternoon.
  • Greg: Set the lab due date for Wednesday and communicate the deadline to students.

Summary

Rust Autograder Timeout Fix

  • The meeting addressed a hard-coded 30-second timeout in the autograder affecting both Python and Rust, with Rust builds taking longer due to dependency downloads and compiler checks (especially on slower hardware).
  • Greg will remove or adjust the timeout to avoid penalizing Rust submissions while maintaining fair grading.
  • The class also emphasized strict adherence to calling conventions to ensure compatibility with other compiled or generated code.
  • More detailed coverage, including in-class examples, is planned for Week 6.

Assembly Function Call Execution Flow

  • The execution flow of function calls in assembly was reviewed:
  • PC is a special register implicitly managed by the processor during jumps/calls/returns.
  • RA holds the return address and must be preserved across function calls to ensure correct returns.
  • Upcoming course components include:
  • A lab on larger functions and recursion
  • A project involving string data and a code generator for NT-lang

RISC-V Function Call Mechanics

  • The mechanics of function calls in RISC-V were explained with an emphasis on stack usage:
  • Caller-saved registers: a0–a7, t0–t6, ra (may be modified by the callee; the caller must save them if needed across a call).
  • Callee-saved registers: s0–s11 and sp (the callee must preserve and restore them if modified).
  • The function call “contract” guarantees that callee-saved registers remain unchanged after a call.
  • Examples illustrated how to save/restore registers and manage the stack frame correctly.

Rust Compiler’s Argument Handling

  • For functions with more than eight arguments, the Rust compiler (similar to C compilers) places additional arguments on the stack.
  • When calling external or assembly functions, the compiler:
  • Generates the necessary stack setup for arguments beyond a0–a7
  • Uses appropriate calling modes/annotations to align with the callee’s expectations

Stack Allocation and Register Usage

  • In assembly, programmers or compilers must explicitly allocate stack space for arguments and local data.
  • Differences between unoptimized and optimized code were highlighted:
  • Unoptimized code may spill values to the stack more often.
  • Optimized code prefers register usage and minimizes memory traffic.
  • Proper stack frame layout and preservation of caller-saved registers are critical.
  • An example demonstrated adding four arguments using a caller-saved approach, focusing on:
  • Allocating stack space as needed
  • Preserving volatile registers across calls
  • Returning results in a0

Assembly Language Recursion Overview

  • Recursion in assembly was explored using a factorial example:
  • Return addresses and local variables are stored on the stack at each recursive call.
  • GDB was used to step through recursive frames and observe stack changes.
  • The session reinforced:
  • Correct handling of caller-saved vs. callee-saved registers
  • Proper argument passing and return value conventions
  • Strict adherence to calling conventions to avoid subtle bugs
  • A recursion problem will be included in the next lab, due Wednesday.