Skip to content

Instantly share code, notes, and snippets.

@robert-saramet
robert-saramet / riscv_guide_1.md
Created July 19, 2025 10:11
Comprehensive Guide to 32-Bit RISC-V Assembly Programming (RV32I)

Comprehensive Guide to 32-Bit RISC-V Assembly Programming (RV32I)

This guide provides a thorough introduction to programming in 32-bit RISC-V assembly language, focusing on the RV32I base integer instruction set. It starts with content from this cheat sheet and expands it into a complete, structured reference. The guide is organized for easy navigation, with clear sections, tables for listings, explanations, examples, and notes. It draws from official specifications and tutorials to ensure accuracy and completeness. Beginners can follow sequentially, while experienced users can reference specific sections.

Key assumptions:

  • We use the GNU Assembler (GAS) syntax, common for RISC-V tools.
  • Examples assume a bare-metal or simple simulator environment (e.g., RARS, Spike, or QEMU).
  • RV32I is the base; extensions like M (multiply/divide) are noted but not required unless specified.
  • Code snippets are testable in simulators; error handling and overflows are ign

How to convert markdown to PDF:

This post reviews several methods for converting a Markdown (.md) formatted file to PDF, from UNIX or Linux machines.

Using Pandoc:

$ pandoc How_I_got_svg-resizer_working_on_Mac_OSX.md -s -o test1.pdf
@robert-saramet
robert-saramet / solutions_modern_approach.c
Last active March 28, 2024 15:36
My solutions to certain exercises inspired by the book 'C Programming: A Modern Approach - Second Edition'
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void nth_suffix(unsigned int n, char suffix[]) {
if (n > 10 && n < 20) {
strcpy(suffix, "th");
return;
@robert-saramet
robert-saramet / armstrong.c
Created March 24, 2024 12:09
My solution to exercism.org/tracks/c/exercises/armstrong-numbers
#include <math.h>
int digits(int n) {
if(n < 10) return 1;
if(n < 100) return 2;
if(n < 1000) return 3;
return 3 + digits(n / 1000);
}
bool is_armstrong_number(int candidate) {
@robert-saramet
robert-saramet / isogram.c
Created March 24, 2024 11:23
My solution to exercism.org/tracks/c/exercises/isogram
#include <string.h>
#include <ctype.h>
bool is_isogram(const char word[]) {
if(word == NULL)
return false;
int count['z' - 'a' + 1] = {0};
for(size_t i = 0; i < strlen(word); i++) {
char c = tolower(word[i]);
if(c >= 'a' && c <= 'z')
#include <stdio.h>
#define FREEZING_POINT_K 273.15f
#define FREEZING_POINT_F 32.0f
#define F_TO_K_RATIO (5.0f / 9.0f)
#define DEGREE_SYMBOL 248
enum Unit { Kelvin, Celsius, Fahrenheit };
@robert-saramet
robert-saramet / dimensional_weight.c
Created March 21, 2024 06:51
First C program: reads properties of a shipment and prints chargeable weight taking volume into account.
#include <stdio.h>
#include <string.h>
#define INTERNATIONAL_TRESHOLD 166
#define LOCAL_TRESHOLD 194
int calc_volume(int length, int width, int height) {
return length * width * height;
}
@robert-saramet
robert-saramet / string_vs_str.rs
Created April 10, 2023 10:48
Comparison between the String and str types in Rust, including example functions and the effects of how the parameters are passed. This is only my understanding as a beginner and I'm not sure everything is correct.
// Idiomatic
// Modifies string_var in place; doesn't return anything
// The original string_var remains valid
fn takes_string_ref_no_return(string_var: &mut String) {
string_var.push_str("world");
}
// Idiomatic
// Returns a new owned String
// The original str_var also remains valid
@robert-saramet
robert-saramet / batdir.fish
Last active March 21, 2023 17:13
Fish command to print all files in directory using bat. Unorthodox code.
function batdir --description 'Print all files in directory using bat'
if not count $argv > /dev/null
set path .
else
set path (string trim -r -c / $argv)
end
for file in $path/*
bat -P $file 2> /dev/null
end
end
@robert-saramet
robert-saramet / serial-plotter.go
Last active March 23, 2023 23:08
Go serial plotter using raylib. Ever-so-slightly inspired by ChatGPT
package main
import (
"bufio"
"errors"
"github.com/gen2brain/raylib-go/raylib"
"github.com/tarm/serial"
"log"
"os"
"strconv"