What is RISC-V Bit-Golf?

Bit-Golf is a form of code golf where the goal is to minimize the number of '1' bits in the machine code representation of a program. This site uses the RISC-V RV32I instruction set.

The Virtual Machine

The RISC-V VM has 4KiB of instruction memory, which cannot be accessed, and 1024KiB of little-endian data memory, which is mapped from 0x00000000 to 0x000FFFFF. The VM has support for all RV32I instructions and pseudoinstructions listed on this page.

The Editor / Assembler

The Assembler has the following features:


Single-line comments: use ; to begin a single-line comment. Any text after and including the ; will be ignored.

Breakpoints: use a right carat > before an instruction to set a breakpoint.

Labels: use a series of non-whitespace text followed by a colon : to create a label. Labels can be used instead of immediates in jump and branch instructions. Labels cannot start with a number.

Step: use [ctrl]+, to execute one instruction at a time.

Run until breakpoint: use [ctrl]+. to execute until the next breakpoint is reached.

Execute: use [ctrl]+/ to run the program until it exits or times out.

Smart indentation: [tab] and [backspace] will automatically align whitespace to multiples of four characters. The commands [ctrl]+] and [ctrl]+[ allow you to indent or dedent multiple lines at once.

Getting started

The Bit-Golf game on this site uses the base RV32I instruction set - which means no builtin multiplication or division or floating point arithmetic, etc. There are two special system call functions: INPUT and OUTPUT. INPUT RD takes the next value from the input queue and writes it to register RD. If the input queue is empty, -1 is written. OUTPUT RS halts execution, returning the value contained in RS.

> See the supported instruction set and VM features here <


One way to get started is to write your code in C, and compile it to RISC-V using GodBolt. I recommend using the -O2 flag. Be aware that the RISC-V VM only supports memory access from 0x00000000 to 0x000FFFFF - this is especially important if you don't use -O2, as the stack pointer will underflow.

Play: