RASP compiler is included in the architecture of the RASP virtual computer in emuStudio. Its purpose is to translate the source code of a RASP program into the form executable by the RASP CPU emulator.
It includes a lexical analyzer which is responsible for recognizing lexical units within the source code. It also enables syntax highlighting. Then, the code goes through syntax analysis which checks for syntax errors and builds up the syntactic tree. The tree is then passed through and binary code executable by the emulator is generated.
As with the other emuStudio compilers, you start the compilation by the “Compile source” icon in the main menu. The result of the compilation is saved into a binary file with the
.bin extension and also loaded into the RASP operating memory.
As RASP is a von-Neumann computer, both the program and the data reside in the same memory module. Therefore, we need to specify, where the program start address is as CPU must know where to start emulation. We do so by the
org directive followed by a positive integer. The program start definition must be the first line of the source code. Please, do not place any empty lines before it. Here, an example follows:
WARNING: If you do not specify the program start address, or if you set it to
org 0), the default value will be used, which is
20. The compiler will warn you about this, so do not worry. Setting program start to
0 is not allowed as register
R0 is used as the accumulator and therefore any instruction written here would be overwritten sooner or later.
All RASP emulator supported instructions together with their semantics are available in the RASP CPU documentation. There are three types of operands of those instructions:
- register - e.g.
- constant - e.g.
WRITE =2- you specify that operand of instruction should be interpreted as a constant by the
- label, which is the operand of jump instructions (
Each RASP instruction with its operand MUST be on a separate line, otherwise, the code will not compile.
A single line of code consists of instruction followed by its operand. The line can be optionally started with a label. It is possible to put the label and the instruction on two separate lines, however, please, do not place any empty lines between the label and the instruction.
WRITE 2 can be on a separate line):
*labelName:* WRITE 2
RASP compiler supports one-line comments. You start them with a semicolon (
;this is a comment
You can append a comment to an existing line, e.g.
write 2 _;comment_
or put it on a completely new line.