Skip to content

rithiksachdeva/Computer-Architecture

Repository files navigation

RISC-V Computer Architecture Lab

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).

What this repo is for

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.

Features (by assignment batch)

Program File Summary
Leap year lpyear.asm Signed year in x101 / 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 x101 / 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).

Tech stack

  • Language: RISC-V RV32I assembly
  • Tooling: RARS (RISC-V Assembler and Runtime Simulator)
  • Platform: Cross-platform (Java-based simulator)

Project structure

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

Setup

  1. Install a JDK (11+ recommended) if you do not already have one.
  2. Download RARS from the official releases.
  3. Open RARS, load an .asm file, assemble, then run or single-step as needed.

How to run (typical RARS workflow)

  1. Assemble the file (assemble in RARS).
  2. Initialize registers for arguments (see table above and each file’s header comment).
  3. Set pc to a small test harness that jals to the global symbol (e.g. lpyear, gcd, division, max_xor).
  4. Run and inspect a0/x10 (and other result registers where applicable).

There is no bundled automated test suite; verification is manual in the simulator.

Example usage (conceptual)

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).

Configuration / environment

No environment variables or build files are required. All programs are plain assembly for RARS.

Testing

  • 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.).

Known limitations

  • Performance: Prime search (npnum.asm) and insertion sort on 1024 elements (insert.asm) are correct for modest inputs but are intentionally slow for large N or 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.

Future improvements (optional)

  • Small RARS macro or test stub files per program for repeatable checks.
  • Unified naming (division vs filename div.asm) only if you control the grader/linker script.

License

This repository is not licensed for reuse. If you need to fork or redistribute, add a license (e.g. MIT) explicitly.

Acknowledgments

Course context: Computer Architecture (UC Davis–style curriculum), Winter 2020 cohort work, adapted for clarity and presentation on GitHub.

About

Self-contained RISC-V RV32I assembly for the RARS simulator: integer utilities, string parsing, sorting (selection, insertion, merge), division without div/mul, max pairwise XOR, and predecessor search. Educational portfolio snapshot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors