Small, self-contained RISC-V RV32I assembly programs written for the RARS simulator. They were originally developed for an undergraduate computer architecture course and implement classic integer, string, and array problems with explicit register-based calling conventions (no high-level runtime).
Each .asm file exports one global label that acts as a callable routine. Typical use in RARS: assemble the file, set argument registers (a0/x10, a1/x11, … as documented per program), jal to the label, then read the result from a0/x10. This is a learning and portfolio snapshot of low-level problem solving—not a production library.
| Program | File | Summary |
|---|---|---|
| Leap year | lpyear.asm |
Signed year in x10 → 1 / 0 / -1 if invalid (non-positive). |
| GCD | gcd.asm |
Unsigned x10, x11 → GCD in x10, or -1 if either input is 0. |
| Nth prime | npnum.asm |
Unsigned N in x10 → Nth prime, or -1 if N == 0. |
| Hex palindrome | palin.asm |
Unsigned word in x10 → 1 / 0 / -1 for 0. |
| String to int | atoi.asm |
Address of null-terminated string in x10 → value or -1 on bad input. |
| Selection sort | sort.asm |
In-place sort: array address x10, length x11. |
| Division | div.asm |
Dividend x10, divisor x11 → quotient x10, remainder x11 (no div/mul/rem in the algorithm as required). |
| Max XOR pair | xor.asm |
Array x10, length x11 → maximum a[i] XOR a[j] in x10. |
| Insertion sort | insert.asm |
1024 words: input a1, output a0 (sorted). |
| Merge sort | merge.asm |
1024 words: output a0, input a1 (iterative merge; see file comment for a2). |
| Predecessor search | bsearch.asm |
Sorted 1024-word layout + key: walk per lab spec; result communicated via a0 as the harness expects (see file header). |
- Language: RISC-V RV32I assembly
- Tooling: RARS (RISC-V Assembler and Runtime Simulator)
- Platform: Cross-platform (Java-based simulator)
Computer-Architecture/
├── README.md
├── .editorconfig
├── .gitignore
├── lpyear.asm, gcd.asm, npnum.asm, palin.asm # Set 1
├── atoi.asm, sort.asm, div.asm, xor.asm # Set 2
├── insert.asm, merge.asm, bsearch.asm # Set 3
- Install a JDK (11+ recommended) if you do not already have one.
- Download RARS from the official releases.
- Open RARS, load an
.asmfile, assemble, then run or single-step as needed.
- Assemble the file (
assemblein RARS). - Initialize registers for arguments (see table above and each file’s header comment).
- Set
pcto a small test harness thatjals to the global symbol (e.g.lpyear,gcd,division,max_xor). - Run and inspect
a0/x10(and other result registers where applicable).
There is no bundled automated test suite; verification is manual in the simulator.
For gcd.asm: put two non-zero unsigned values in a0 and a1, call gcd, read the GCD from a0. Exact register names may match course specs (x10/x11 are the same physical registers as a0/a1 in RV32).
No environment variables or build files are required. All programs are plain assembly for RARS.
- Automated: None in this repository.
- Manual: Assemble each file in RARS and exercise edge cases described in the course specs (zeros, negatives where applicable, empty/invalid string for
atoi, etc.).
- Performance: Prime search (
npnum.asm) and insertion sort on 1024 elements (insert.asm) are correct for modest inputs but are intentionally slow for largeNor worst-case data—documented in the source where relevant. - Scope: Code targets educational constraints (specific algorithms, forbidden instructions in some labs).
- Calling convention: Routines are written for isolated grading; some use extra callee-saved registers without full saves in every path—fine for single-shot tests, not a general ABI.
- Small RARS macro or test stub files per program for repeatable checks.
- Unified naming (
divisionvs filenamediv.asm) only if you control the grader/linker script.
This repository is not licensed for reuse. If you need to fork or redistribute, add a license (e.g. MIT) explicitly.
Course context: Computer Architecture (UC Davis–style curriculum), Winter 2020 cohort work, adapted for clarity and presentation on GitHub.