Skip to content

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

  • Date: Sep 18, 2025
  • Time: 08:19 AM Pacific Time (US and Canada)
  • Meeting ID: 886 4953 2573

Quick Recap

  • Greg covered RISC-V memory instructions with emphasis on load/store operations, signed vs. unsigned loads, and struct memory layout.
  • He introduced linked lists (singly and doubly), their properties, and implementations in C and assembly, including memory allocation and pointer manipulation.
  • The session concluded with Project 3 guidance (FindMax), interactive grading logistics, and feedback on student code.

Next Steps

  • Submit practice problems as a PDF named “problems.pdf” in the Lab4 repository by tomorrow night.
  • Review and understand struct memory layout, offsets, and alignment for Project 3.
  • Implement the FindMax function for Project 3 using linked-list traversal.
  • Use the appropriate RISC-V load instruction based on whether struct fields are signed or unsigned.

Summary

RISC-V Memory Instructions Overview

  • Focus on load instruction variants and sign extension:
  • Signed vs. unsigned loads: LB (load byte, signed) vs. LBU (load byte, unsigned).
  • Sign extension matters for correctly handling negative values.
  • Store instructions (SB, SH, SW, SD) do not have unsigned variants, as they write register values to memory without sign extension.

Struct Memory Layout and Access

  • The compiler adds padding to ensure proper alignment, especially for 4-byte word loads (addresses must be multiples of 4 when required).
  • Correctness requires matching load instruction to the field’s type and size (e.g., byte, halfword, word).
  • Topics covered:
  • Calculating offsets for struct fields.
  • How struct positions and pointer offsets relate in memory.
  • Practical examples in both C and assembly.

C Structs in Assembly

  • Demonstrated field access from assembly using computed offsets.
  • Corrected examples to use unsigned integers appropriately when required.
  • Emphasized understanding how C struct definitions map to memory layout and assembly operations.

Using Correct Load Instructions for Struct Fields

  • Key point: choose LB/LH/LW vs. LBU/LHU/LWU based on field signedness.
  • Example showed incorrect results when using LB instead of LBU due to sign extension.
  • Takeaway: always align the load instruction with the field’s declared type.

Break and Submission Reminders

  • A 7-minute break occurred before the linked lists topic.
  • A guest speaker from San Francisco State will discuss generative AI and teaching.
  • Practice problems are due the next day as a PDF named “problems.pdf” in the Lab4 repository.
  • Formatting requirements are strict to avoid submission issues.

Linked List Concepts

  • Singly vs. doubly linked lists:
  • Doubly linked lists support efficient backward traversal and O(1) removals from the middle, while singly linked lists can require O(n).
  • Emphasis on low-level understanding in assembly, where language abstractions are removed.

C Linked List Implementation Basics

  • Node layout considerations:
  • Pointers typically occupy 8 bytes; integers occupy 4 bytes.
  • Manual construction on the stack:
  • Created nodes N0, N1, N2, N3 with values 11, 22, 33, 44 and linked via next pointers.
  • Demonstrated how to compute and use field offsets.

Linked List Assembly Demonstration

  • Translated a C function to assembly to count nodes in a linked list.
  • Discussed:
  • Register usage and calling conventions.
  • Memory offsets for node fields.
  • Loop control, pointer advancement, and memory access patterns.
  • Prepared to use GDB to examine memory layout and verify behavior.

Linked List Memory Tracking Demo

  • Technique for inspecting memory and following pointer chains.
  • Each node struct: 16 bytes total (including 4 bytes of padding).
  • Observed pointer behavior during traversal:
  • Effective stride of 16 bytes per node (accounting for pointer field, value field, and padding).
  • Validated memory allocations and updates during traversal.

FindMax Project and Grading Preparation

  • Discussed project complexity, especially around print calls and adherence to calling conventions.
  • Interactive grading:
  • Sign-up sheet opens Monday for Tuesday sessions.
  • Students should arrive prepared: repo cloned, terminal/editor ready, and able to explain design choices.
  • Code feedback example:
  • Simplified approach: multiply the result by 10 at the start of each loop iteration, then add appropriately in subsequent steps.