Blinking LEDs with RISC-V assembly

Sat, Aug 31, 2019 | tags: RISC-V programming assembly

My educational background is mostly in linguistics so I only gained a very theoretical understanding of the nitty-gritty details of assembly language during my studies. Lately (in my part of the internet) there was quite a buzz about the RISC-V ISA (Instruction Set Architecture). I read up about this RISC ISA and in typical me-fashion got so excited that I ordered both the RISC-V Reader-book (which I would recommend!) and one of the first available RISC-V microcontroller dev boards, the Hifive 1 Rev B.

My main goal was to use this microcontroller to get some first-hand practical experience writing assembly language. Instead of going with x86-64 assembly, RISC-V promised to be much more approachable since it was touted to be a more elegantly designed and easier to use RISC instruction set architecture.

The first thing I did once I finished reading the RISC-V Reader was going through the RISC-V assembly video tutorial that WD put up on Youtube. WD seems to be quite invested in RISC-V and them putting up this video tutorial is a great contribution to the RISC-V ecosystem. I did not use the same development environment as in the video series (there they use PlatformIO) but instead opted for the bare Freedom E SDK provided by Sifive (the makers of the Hifive1 boards). My development environment consisted of Vim, misappropriated Makefiles from the Freedom E SDK and the RISC-V compiler toolchain from Sifive. Regardless of the differences in our development environments, the code in the video tutorial worked well for me (you can download the version I typed out from here).

After following the video tutorial it was time to write some RISC-V assembly for myself. I thought an appropriate first step would be to write an interrupt service routine (ISR) instead of relying on a busy loop to blink the LEDs on the board. It took me about three weeks (and quite a bit of help from friendly strangers on the internet) until I got my LEDs to blink in a slightly more efficient way. In case you, dear reader, are interested in seeing my bad assembly code in my hacked-together fork of the Freedom E SDK, have a look here. The result looks like this.

The next thing to try would be a project making proper use of the capabilities of this microcontroller board. What somewhat tempts me is a project involving a GUI on a small (LCD) screen. Somehow the thought of writing a GUI controlled by a device like this with 16KB of RAM is fascinating to me…

Another point of interest for me is the RISC-V port of Go. The current status is documented on this helpful page. It’s unlikely that I will be able to contribute a lot to these efforts but I hope that I will at least be able to help with testing.

Don't hesitate to send comments and/or questions to my public-inbox.