Skip to content

CS 315-02 Lecture/Lab Meeting Summary (Fall 2025)

  • Date: Sep 17, 2025, 06:36 PM Pacific (US and Canada)
  • Meeting ID: 868 6589 0521

Quick Recap

The session outlined: - Plans for the upcoming lab: work on practice problems and Project 3. - A detailed walkthrough of structs and their use in assembly. - Common challenges with GDB and a proposed lab activity to strengthen debugging and memory-model understanding. - Explanations of writing assembly functions, RISC-V memory addressing, and C struct/array access using pointers and offsets.

Next Steps

  • Ensure the Project 3 starter code is present in each project tree.
  • Resolve any Project 3 starter code issues immediately.
  • Learn and practice GDB for interactive grading.
  • Call the C library string-length function from assembly for Project 3.
  • Follow calling conventions correctly when using printf in Project 3.

Details

Lab Session and Project Updates

  • The instructor emphasized using lab time for practice problems or Project 3.
  • All students should have received Project 3 starter code; any issues should be resolved promptly.
  • The lesson focused on structs and their interaction with assembly.
  • Students were reminded to mirror C program structure when working with strings in assembly.
  • The session introduced calling the C library string-length function and discussed using printf from assembly, noting the added complexity.
  • A reference to the RISC-V guide on the course website was provided for further study.
  • Reminder: follow calling conventions.

Enhancing GDB Learning Experience

  • Students commonly avoid GDB due to time pressure and perceived complexity, despite its value in problem-solving.
  • The instructor reviewed basic GDB commands and proposed a lab activity requiring students to demonstrate stepping through execution.
  • Emphasis was placed on developing a mental model of instructions, memory, and control flow; GDB aids this, even if it can be limited in memory visualization.

Assembly Function Writing Basics

  • Introduced DATA directives and the .string directive for creating string literals.
  • Explained the need for the global directive when calling external functions (e.g., printf).
  • Covered stack setup for function calls and passing arguments (e.g., using register a0 for the first argument).

C Compiler Address Loading Mechanism

  • Explained how the compiler uses the LA pseudo-instruction to load 64-bit addresses into a0 for pointer operations.
  • Described how assemblers handle 64-bit constants with 32-bit instructions by placing full constants in memory and using LA to materialize addresses, requiring multiple steps due to instruction size limits.

Assembly Programming and printf Basics

  • Demonstrated a standalone assembly program calling printf with format specifiers.
  • Showed how to pass integers and strings to printf.
  • Emphasized preserving caller-saved registers around function calls.
  • Announced that the next class will continue with structs, including a review of related concepts.

C Arrays and Structs Overview

  • Arrays: contiguous collections of elements of the same type.
  • Structs: composite types that can contain fields of different types, including arrays and other structs.
  • Emphasized understanding memory layout for correct pointer arithmetic and field access.
  • Introduced a Node struct concept (discussion to be completed in a future session).

C Struct Memory Access Techniques

  • Demonstrated accessing struct members via pointers:
  • Example: if a Node stores X in the first 4 bytes and Y in the next 4 bytes:
    • a0 holds the pointer to the Node.
    • Load X with a word load from 0(a0).
    • Compute Y’s address as a0 + 4 and load with a word load.
  • Reinforced using correct offsets relative to the base pointer.

RISC-V Memory Addressing and Alignment

  • Reviewed calculating offsets for array elements and struct members.
  • Discussed alignment requirements for different data types and how misalignment affects access.
  • Noted that the C compiler inserts padding to satisfy alignment within structs.
  • Office/lab availability: the instructor and Travis will be available during lab for questions; students are encouraged to use the time for Project 3 support.