Skip to content

CS 631-01 Systems Foundations — Meeting Summary

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

Quick Recap

The session focused on RISC-V assembly fundamentals, including calling conventions, register usage, stack management, and bitwise operations. Highlights: - Caller-saved vs. callee-saved registers; stack discipline. - String manipulation in assembly (ASCII, load/store byte, string length/copy). - Endianness: little-endian vs. big-endian. - Bitwise operations, bit extraction, and sign extension. - Rust-to-assembly examples, including overflow checks in debug builds. - Introduction to bit packing; students will implement packing independently.

Next Steps

  • Greg: Share the intended Rust implementation of insertion sort (with swap) for reference.
  • Greg: Clarify that students must call their own swap in the insertion sort assignment.
  • Greg: Send links to Rust Playground and Godbolt Compiler Explorer.
  • Greg: Push the latest PICO code (including API key handling) to the class repository.

Detailed Summary

Calling Conventions and Register Management

  • Reviewed Lab 4 and prior material on calling conventions.
  • Explained caller-saved vs. callee-saved registers and why adherence matters for interoperability with compiled C code.
  • Noted upcoming demonstration: calling compiled C from assembly.
  • Examined Rust compiler output to understand safety checks and generated instructions.

Caller-Saved vs. Callee-Saved Discussion

  • Presented trade-offs and expressed a preference for caller-saved conventions for clearer reasoning about function calls.
  • Discussed recursion and swap implementations.
  • Outlined upcoming topics: strengthening assembly skills, bitwise operators, and a Thursday project to add code generation to NTLANG (producing assembly that assembles to machine code).

Computer Memory and Byte Ordering

  • Reviewed memory layout and how multi-byte values are stored.
  • Explained little-endian vs. big-endian using hexadecimal examples.
  • Mentioned JIT compilation as in-memory code generation analogous to assembling and executing generated code.

Byte Ordering in Computing Systems

  • Showed how to detect endianness using Rust.
  • Emphasized that endianness matters beyond CPUs, including network protocols (e.g., TCP/IP), which use network byte order (big-endian).

Internet Context and Assembly Language Basics

  • Briefly discussed the internet’s role in distributing knowledge and the relevance to large language models.
  • Explained network byte order conversions across architectures.
  • Transitioned to string operations in assembly:
  • ASCII character codes.
  • lb/sb (load/store byte) to access bytes in memory.
  • Load instruction syntax and signed vs. unsigned loads for sub-word sizes.

Rust vs. C String Handling

  • Compared Rust and C strings:
  • Rust uses string slices and heap-owned strings with explicit length; no null terminators.
  • C uses null-terminated strings.
  • Demonstrated assembly for string length and copy:
  • Process data in registers first, then write back to memory (RISC load/store architecture).

Assembly “Hello, World” Demonstration

  • Implemented a minimal example showing:
  • Function calls, stack setup/teardown, and data declaration.
  • Using the la pseudo-instruction to pass a string pointer to printf.
  • How compilers expand la into actual addressing instructions.
  • GCC-generated prologue/epilogue and stack operations.

Bitwise Operators in RISC-V

  • Reviewed data declarations: .byte, .half, .word, .dword, .string.
  • Discussed mixing strings and words in data sections and how to label and load addresses.
  • Noted a pending question about storing mixed data under one label; testing was inconclusive due to technical issues.

Code Formatting and String Handling

  • Clarified use of commas in data declarations and the role of null terminators in C-style strings used by printf.
  • Emphasized careful register management when initializing multiple labeled data attributes.
  • Mentioned ongoing PICO code setup, version control, and repository structure updates.

Rust Code and Bitwise Operations

  • Compared an intended Rust implementation to an alternative design:
  • Rust strings carry their length; no need to pass length separately.
  • Demonstrated idiomatic Rust loops with iterators vs. C-style loops.
  • Covered RISC-V shifts and bitwise ops:
  • Logical vs. arithmetic shifts.
  • 64-bit operations vs. 32-bit variants using the W-suffixed instructions.

Bit Sequence Extraction in Assembly

  • Demonstrated extracting a bit range from a 32-bit value:
  • Constructed a mask: shift a sequence of 1s by (bit-length − 1), then align to the target range.
  • Shifted the value to align the desired bits to position 0.
  • Corrected an initial mistake: the shift amount must be computed dynamically based on the requested bit range, not a fixed constant.

Sign Extension and Compiler Analysis

  • Showed sign extension of a small bit-width value (e.g., 4-bit) to 32 bits via shifts:
  • Shift left to move the sign bit into the high position, then arithmetic shift right to fill.
  • Used Rust Playground and Godbolt to inspect compiler-generated assembly:
  • Noted Rust debug mode’s overflow checks (e.g., in multiplication).
  • Resolved minor tool issues during the session.