RISC V ASM Tutorial | Part 1 of 12 | Introduction

RISC V ASM Tutorial | Part 1 of 12 | Introduction

Hey everybody, my name is Martin and this
is a video series to give you a tutorial on assembly language with RISC-V.
We’re going to do just some very basic stuff to get you going with assembly
language, and I’ve cut this up into a number of different videos so that way
you can just go to the videos if you kind of have to stop and and come back;
make it easy to keep going from where you started. This is just the
introduction to give you an idea of what we’re going to be doing and how we’re
going to be doing it and so let’s get going. So basically what we’re going to
be doing is building a small project. You’ll see I call it Super Blink, where
we’re just gonna blink some LEDs on a microcontroller board. So for this video,
I’m kind of assuming that you have a little bit of experience doing stuff
with microcontrollers like Arduino, ST Micro, Expressive, and those kinds of
controller boards, and that you’ve got some software development experience. So
if you’re completely new to programming microcontrollers, or you’re completely
new to programming, this is probably not the best video to get started. But
assuming you’ve got some of that background, this is how we’re going to
get started. So we’re going to use Visual Studio code which is a text editor that
allows us to do all of our actual code development. Now I’m not going to give
you a tutorial on Visual Studio Code: If you’re new to Visual Studio code
you should probably stop here. There’s a whole bunch of videos on YouTube that’ll
get you going. If you really want to you can actually use an alternate editor,
there’s probably ten different kinds you can use, but this tutorial is built
around Visual Studio code and uses some of the features like debugging, etc, that
are there. Now we’re going to use an extension to Visual Studio code called
PlatformIO, and actually that’s where really all the power of development
comes here is from PlatformIO because it is a tool that allows you to develop
for almost any microcontroller you can think of. Any platform you can
think of, any library you can think of. They’re pretty much all well integrated
into PlatformIO and you are going to see that. So I am going to go through and
show you how to install and how to use PlatformIO, but only with Visual Studio code. One of the things you’ll find out here is
PlatformIO can actually integrate into almost any IDE you can think of. So if you
prefer using Atom, or Sublime Text, or Eclipse, or any other cloud IDE, the odds
are that PlatformIO can integrate in and so if you really want to do that you can
go ahead and do it that way. Again, for this tutorial we’re going to focus on
PlatformIO as an extension to Visual Studio Code. Now in order to write RISC-V
assembly, we need a RISC-V board, and we’re going to use a board from a
company called SiFive. You can go to sifive.com find out more there, and they
build a cool little board called the HiFive1, which you can see on the
screen, and the HiFive1 is a Arduino format. So Arduino makes these
hardware formats called R3 if I remember correctly, and this is an R3 formatted or
form-factor board that has a RISC-V processor, and that’s what we’re going to
use in order to build our first round of assembly language. Now we’re going to go
through and I’m going to show you how to integrate some documentation that we’re
going to use, but just as a mode of background, if you’re completely new to
RISC-V, RISC-V is an open source instruction set architecture. I wanted to
point you to some resources that you can go look at in order to learn more about
RISC-V. So the first two are books that you can get either in paperback or
hardcover, I can’t remember which, but you can get printed copies of these books
from Amazon and I think both of them also have digital copies. You can get
them for your Kindle or what have you. Those will go into the depths of
computer architecture and the interesting thing is that they use RISC-V as their foundation to talk through computer architecture. So in some ways
they’re not really RISC-V books, but they are books more about learning how
computer architecture is done, and they just happen to use RISC-V as the
foundational instruction set to help you learn that.
The third book called the ‘RISC-V Reader’ at least at the point at which
I’m doing this video, is only available in paper copy, and so I would strongly
encourage you, it’s not very expensive, to go to Amazon get your copy because I do
use some stuff from that book and because it’s only a printed copy, I won’t
be able to show you exactly, or copy and paste from it, but you’ll have to trust
me that the stuff that I’m doing is actually from this book and so that’s
why I really would encourage you to get a copy of this book. So what we’re going
to do in this tutorial is we’re going to build something called superBlink, and
the reason why I call it superBlink is that in the microcontroller world, the
equivalent of a “hello world” application is blink the LED on your microcontroller.
And so if you’ve done any kind of microcontroller development you’ll know
that the first thing you do is try to blink the LED, and that just verifies
that you’ve got a hardware connection that works, and that your development
environment also works. And the reason I call it superBlink is we’re gonna do a
couple of things that go beyond the traditional “hello world” or just blink
the LED. First thing is the HiFive1 board has three LEDs. Red, green, and blue,
and we’re going to just blink them in succession. So that’s one thing that’s
going to be a little bit different, rather than just blinking one LED. Now of
course the thing about this tutorial, is it’s about RISC-V
assembly, so almost everything we’re gonna do is going to be written in RISC-V assembly and that’s not typical for the microcontroller ‘hello world’ type of
application. and so in our case we’re going to do most of this in RISC-V
assembly. But the other thing I wanted to show you was how you could actually
write most of your code in RISC-V assembly but call it from C code. And so
our main routine is really going to be written in C, it’s going to be very simple,
but in that C code we’re going to call some functions but those functions are
going to be written in an assembly language and you’re going to see through
how we do that, and how all that comes together. And then the other thing is
we’re going to use the features of PlatformIO integrated with VS code, or
Visual Studio code, in order to actually debug
and single step through our assembly language code, so that we can actually
see what’s happening as we go along. And parts of this of course happen on the
microcontroller board, so I’ve included a little video here that you should see on
the inset that shows you this led sequence blinking, but that’s really
simply what we’re going to go do. So that’s our project, that’s what we’re
going to go do. That’s it for the introduction. Get to part two and we’ll
start setting up our environment so that we can do our assembly language

3 thoughts to “RISC V ASM Tutorial | Part 1 of 12 | Introduction”

  1. This is a really nice series of videos, although perhaps it is more "generic" about setting up an embedded system development environment and writing some basic code, than about the RISC-V specifically.

  2. RISC V really doesn't have any good IDEs. Eclipse based IDEs crash constantly, Embedded Studio has a horrible GUI and doesn't support all combinations of ISA extensions and PlatformIO doesn't have free debugging.

  3. I have created the files in the video (with some small changes in naming and the C code) and put them up for download here: https://sillymon.ch/data/riscv-assembly-language-tutorial.zip feel free to download them if you are too lazy to type the files in the video out

Leave a Reply

Your email address will not be published. Required fields are marked *