VHDL implementation of the RRISC CPU

A small CPU with a radically reduced instruction set. Hand-crafted. Implemented in VHDL, for use in an FPGA.

Download as .zip Download as .tar.gz View on GitHub

RRISC Assembler - writing programs

To translate assembly programs into machine code you use the assemler asm.py provided in the GitHub repository.

Given source code test.asm, you invoke the assembler simply via:

python asm.py test.asm

The RRISC assembler is a macro assembler, which means it can expand macros on a textual basis, sparing you from repetetively writing nearly identical blocks of code.

The first program

Consider the following first little program:

Here we see:

The program just loads the value $ca, stores into RAM at address data, thus overwriting the value $ff there, reads it back into register b and then loops forever by jumping to loop_forever.

When you run the assembler on the above code, you get the following output:

$ python asm.py simtest.asm

Symbol Table:
loop_forever         : 0009
data                 : 000c

Generating: simtest.lst
Generating: simtest.sym
Generating: simtest.coe
Generating: simtest.bin
Generating: simtest.bit
Program size: $000d bytes.

It lists all symbols like data and loop_forever of your program and the values they got assigned during assembling.

Then it generates output files with the following extensions:

The most interesting output file to look at is probably the .lst file:

Note how every assembly instruction is followed by a comment that shows the memory address and the machine code of the instruction.

Using macros

A powerful feature of the assembler is its ability to expand parameterized text macros. Consider the following two files which produce identical machine code compared to our first test program:

Above code also illustrates that you can split your code into multiple files and then just include other files into your main .asm file. The file extension .inc of simtest2.inc is chosen arbitrarily; you do not need to follow that convention.

Here is how you define macros:

To expand a macro:

As you can see in the generated .lst file, @label got expanded to label_2, where _2 is the postfix of the second expanded macro (the first one was testmacro):

^ toc

< RRISC Assembly - introduction

> It runs the whole test program