Skip to content

Chapter 4 — Generating Assembly Programs

Machine language is the set of binary-encoded instructions a processor can execute. Assembly language is the human-readable textual form of machine language. Using mnemonics, programmers can write machine instructions without memorizing encodings and can control hardware directly.

For this lab manual, you do not need to become an expert at handwriting large assembly programs. Before continuing with later processor labs, you should be able to:

  • Understand the basics of the RISC-V ISA (especially the unprivileged RV32I subset): registers, common instruction categories, and naming.
  • Read simple RISC-V assembly and recognize how common control-flow constructs (if, for, while) appear after compilation.

The table below lists RV32I general-purpose registers and their common ABI names.

RegisterABI nameSaved byNotes
x0zeroAlways 0; writes are ignored
x1raCallerReturn address
x2spCalleeStack pointer
x3gpGlobal pointer
x4tpThread pointer
x5–x7t0–t2CallerTemporaries
x8s0/fpCalleeSaved register / frame pointer
x9s1CalleeSaved register
x10–x11a0–a1CallerArgs / return values
x12–x17a2–a7CallerFunction arguments
x18–x27s2–s11CalleeSaved registers
x28–x31t3–t6CallerTemporaries

Table 4.1: RV32I general-purpose registers and ABI names.

This chapter focuses on generating assembly programs using existing toolchains: turning familiar high-level code (e.g., C) into bare-metal RISC-V assembly (no standard library, no OS calls) for use in later labs.