Skip to content

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

  • Date: September 17, 2025
  • Time: 04:58 PM Pacific (US and Canada)
  • Meeting ID: 886 4953 2573

Quick Recap

The session covered: - Parking permits for faculty and students - Project 3: string manipulation in assembly (reverse string) and an introduction to C structs - GDB basics for debugging assembly - Assembly programming concepts: registers, function calls, stack usage, and memory layout for structs - Practical demos: calling printf from assembly, writing a “Hello, World,” and accessing struct members

Next Steps

  • Students:
  • Work on Project 3 during lab time
  • Practice using GDB to debug assembly code
  • Start with the reverse string problem in Project 3
  • Learn how to call printf from assembly
  • Understand how to preserve registers when calling C functions (e.g., printf)
  • Greg:
  • Review structs and linked lists in the next class

Detailed Summary

1) Faculty Parking and Project 3 (Strings)

  • Faculty are guaranteed parking permits; students can purchase permits for $20/day.
  • Project 3 focuses on string manipulation in assembly, analogous to array operations:
  • Use loadByte/storeByte instead of loadWord/storeWord.
  • When reversing strings, do not reverse the null terminator.
  • The algorithm may be in-place or use a destination buffer.
  • Introduction to C structures; deeper coverage planned for the next session.

2) C Programming and Debugging Challenges

  • Review of C composite types: structs and arrays.
  • Discussion of a FindMax function over linked lists, highlighting:
  • Calling conventions
  • Register usage and preservation across function calls
  • Acknowledgment of common hurdles with terminal-based debuggers (e.g., GDB); encouragement of open discussion to lower barriers.

3) GDB and Assembly Debugging Basics

  • Learning curve: benefits often become clear after sustained use.
  • Core GDB commands:
  • break, run, step, next, print, x (examine)
  • Strategy:
  • Set breakpoints at meaningful points (e.g., when a specific array element is loaded)
  • Use continue to advance efficiently
  • Objectives:
  • Build a mental model of machine operations
  • Deepen understanding of assembly instructions and register behavior

4) Assembly Programming and Register Management

  • S registers can be used to retain values across calls, but the caller must preserve them if modified (per calling convention).
  • Example: an add function calling itself illustrates preservation requirements.
  • Data vs. code sections:
  • Define strings in .data
  • Place instructions in .text
  • Calling printf:
  • Set up arguments in the appropriate A registers (A0 for format string; A1–A3 for additional arguments)
  • Preserve caller-saved registers
  • Allocate stack space as needed

5) LA Pseudo-Instruction and printf

  • LA (load address) is a pseudo-instruction used to place the address of a string into a register (e.g., A0) before calling printf.
  • The assembler translates LA into real instructions that load the 64-bit address (often via LD).
  • External functions (e.g., printf) require proper linkage; use directives such as .global as needed.

6) Assembly “Hello, World” Demo

  • Demonstrates:
  • Use of .data and .text sections
  • Calling conventions and register preparation for printf
  • Register preservation beyond RA and SP (e.g., A0–A3 for arguments)
  • Note: Writing entire applications in assembly is possible but not recommended for this course scope.

7) C Struct Memory Allocation

  • Example: struct node with two integers
  • Fields are laid out sequentially in memory, lowest address first.
  • C structs contain no automatic metadata.
  • Padding may be inserted depending on type alignment requirements.

8) Accessing Struct Members in Assembly

  • Access fields (e.g., X and Y in a node struct) using load word with correct byte offsets from the struct’s base address.
  • Concepts apply directly to linked lists (to be reviewed next session).
  • Students are encouraged to begin the reverse string problem to apply these assembly techniques.