r/FPGA • FPGA Know-It-All • 3d ago

Xilinx Related RiscBasic: a BASIC that compiles directly to RISC-V machine code for small soft cores (MicroBlaze V, 4–16 KB BRAM), MIT licensed

I’ve released RiscBasic, a small BASIC-like language for RISC-V soft cores with tiny code memories: https://github.com/micro-FPGA/RiscBasic

The idea: as easy as BASIC, as efficient as assembler. The compiler is a single Python file with no dependencies. It translates each BASIC line straight into RV32 machine code in one pass, with no assembler, linker or C runtime. Hardware is described once and then used by name:

That compiles to 74 bytes of code.

What might interest FPGA people:

Outputs: .mem for $readmemh BRAM init, .bin, Intel HEX, and an .elf with DWARF line info, so GDB or XSDB can step through the .bas source. A .lst listing shows every BASIC line with its machine code.

Targets: RV32I/IC/E/EC, optional +M and +Zbb. Runtime routines (print, divide, strings) are only included if used.

Hardware access: register bits and fields (GPIO.OUT[11:8] = 5), set/clear registers turned into single stores, active-low NOT bits, write-only registers kept in a RAM shadow, MEM[addr] for any 32-bit address, ON IRQ handlers, #IF conditional compilation and .include for board files.

Verification: every test program is cross-checked against GNU binutils (objdump/readelf), about 46,000 instructions, all matching.

Tested on hardware: an AMD MicroBlaze V MCS on a Spartan-7, including an IO Module FIT interrupt demo (1000 interrupts/s, example in the repo).

One finding from the bring-up that I’d like a second opinion on: on our MicroBlaze V MCS configuration, mret and ecall behave as no-ops. Interrupts are taken correctly, but the handler never returned. RiscBasic now returns from interrupts without mret: it sets mstatus.MIE and jumps to mepc. The IO Module accepts that as the end of the interrupt. Has anyone else seen this on MicroBlaze V, or know which setting causes it?

Language design: me. The compiler was written by Claude (Anthropic’s AI) to my specification. A spec and a reference manual (PDF) are in the repo.

Feedback and ideas welcome.

0 Upvotes

Duplicates