Skip to content

fietec/sorts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sorts

A minimal, dependency-free number sorting CLI application written in pure RISC-V 64-bit assembly (RV64M).
This project was a recreational exercise in "bare-metal" userspace programming. The goal was to build a fully functional utility without the safety net of libc.

Features

  • Zero Dependencies: No standard library. Every function - from string-to-integer conversion (stoi) to memory allocation - is implemented from scratch.
  • Memory Management: Uses mmap for dynamic memory allocation to ensure safety across varying input sizes and stack depths.
  • In-Place Sorting: Implements an insertion sort algorithm directly on the heap.
  • Error Reporting: Checks for empty and invalid integer inputs with formatted error messages.

Usage

Since there is no libc to handle file I/O yet, you can use shell expansion to sort the contents of a file:

./sort $(cat numbers.txt)

Use the ./random executable to generate a random test input.

Cross Compilation and Running

To build on a non-riscv machine, install the riscv-gnu-toolchain and compile with

riscv64-linux-gnu-gcc -nostdlib -static -o sort sort.S

or your equivalent.
To run this code on a non-riscv machine, install qemu-riscv64 and run

qemu-riscv64 ./sort <input>

About

A minimal, dependency-free number sorting CLI application written in pure RISC-V 64-bit assembly.

Topics

Resources

License

Stars

Watchers

Forks

Contributors