Meeting Summary: CS 631-01 Systems Foundations¶
- Date: Mar 12, 2026, 08:14 AM Pacific Time (US and Canada)
- Meeting ID: 870 0988 0761
Quick Recap¶
The meeting focused on Project 2, which requires generating RISC-V assembly code from NT-Lang expressions using a stack machine approach. Key points:
- The generated assembly needs a preamble to parse command-line arguments and call C library functions.
- Existing Project 1 code should largely work as-is; the grammar already supports identifiers that can serve as variables.
- The Project 2 specification and tests will be finalized and released the same day.
- The due date is the Wednesday after spring break.
Next Steps¶
- Greg:
- Finalize and release the Project 2 specification and tests by end of day.
- Provide the C version of the preamble for students to translate to assembly.
-
(Optional, in progress) Set up a macOS/Linux environment for running RISC-V code natively.
-
Students:
- Implement Project 2:
- Extend NT-Lang to support compile mode and RISC-V code generation.
- Generate .s assembly files that include:
- A complete preamble (assembly version of the provided C preamble).
- Code generation for expressions using a stack-based approach.
- Handle A-registers as arguments and follow calling conventions.
- In compile mode, restrict identifiers to A-register names:
- Allow only A0–A7 as identifiers and handle them appropriately in code generation.
- Note: Earlier examples referenced A0–A4; the general rule is A0–A7 for argument registers.
Topic Summaries¶
RISC-V Machine Code Emulation¶
- Project 2 is due the Wednesday after spring break; work will then move to RISC-V machine code emulation.
- The discussion covered stack-based evaluation, similar to bytecode interpreters in Java/Python.
- A simple expression was compiled to assembly using a push/pop (stack) strategy.
- Function calls must maintain 16-byte stack alignment (stack pointer multiple of 16).
RISC-V Memory Addressing Basics¶
- Addresses are 64-bit values.
- Memory offsets depend on data size:
- 8-byte (double word) values are spaced 8 bytes apart.
- 4-byte (word) values are spaced 4 bytes apart.
- Examples included pointer arithmetic and address addition.
NT-Lang Compiler Development Overview¶
- The compiler will generate assembly from an AST using a new recursive compile function (not an evaluator).
- A full assembly file must be emitted:
- Static preamble (argument parsing, library calls).
- Dynamically generated code for expressions.
Understanding Compiler Structure and Operations¶
- Components: scanner, parser, code generator → assembler → executable.
- Options for running RISC-V on macOS/Linux without RISC-V hardware were discussed.
- Stack-based operations were compared, including strategies for pushing values and applying unary operators.
- Upcoming deep dive: the preamble’s handling of A-register values (break scheduled before continuing).
Code Optimization and Register Allocation¶
- Non-optimized mode:
- Stores all variables on the stack.
- Optimized mode:
- Maps variables to registers when possible.
- Falls back to memory when register pressure is high, requiring careful management.
- Trade-offs between simplicity and performance were outlined.
Rust “4chan” Implementation Overview¶
- The project requires implementing the “4chan” functionality in Rust only, replacing previous dual-implementation approaches.
- Workflow:
- Convert a C-written preamble to assembly.
- Generate assembly for expressions from Rust (string-based code emission).
- Compile the final assembly with GCC to produce executables.
- Binary operators are handled in code generation; the final result is placed in A0 for the preamble to consume.
Self-Contained Assembly Program Implementation¶
- The goal is a standalone assembly program that runs with C library support.
- Steps demonstrated:
- Allocate and initialize an array on the stack; zero it.
- Populate the array with command-line arguments.
- Use A registers to pass values; follow calling conventions for function calls.
- Project 1 changes are not required; the grammar already supports identifiers.
- In compile mode, the only valid identifiers are A registers (A0–A7; earlier examples showed A0–A4).
- Project 2 spec and tests will be finalized and available by the Wednesday after spring break.
Deliverable Highlights¶
- A working compile mode in the Rust NT-Lang toolchain that:
- Emits valid RISC-V .s files.
- Includes a correct assembly preamble translated from the provided C version.
- Generates stack-based code for expressions.
- Places the final expression result in A0.
- Restricts identifiers to A0–A7 and adheres to calling conventions and 16-byte stack alignment.