A1 - My First Program
This tutorial will walk you through writing an extremely basic program that will execute on the VO-EM console. Not exactly riveting stuff, but it's also very short and simple.
The first thing you will need is a text editor. Any will do, but I recommend Notepad++.
Next, you need the DLX assembler tools by David Knight. You can find them on the VO-EM homepage, here: http://vo-em.com/assembler.php
Then, you will need to have the Java runtime environment installed on your machine. My instructions here assume you're using a Windows machine, but they can be easily adapted for other platforms.
Finally, you need Adobe Flash Player to use the VO-EM debug player on the http://vo-em.com homepage. If you have security concerns, just limit your browser to only allow Flash player to play on the homepage. VO-EM does not contain any advertising, so you do not need to be concerned about flash-based drive-by downloads and the like on this domain.
Writing your program
This is probably going to be the simplest program you ever write. If you've tried reading through the assembly docs, you might want to see if you can write it yourself before reading on.
We will simply do the following:
Add 3 to 5 Store the result in register 3 halt execution
The source code for the program follows. Note that there are many ways to do this, so if you get the right output from your own attempt, you're not wrong.
.start main ;tells VO-EM to start from the instruction labeled 'main' main addi r1,r0,3 ;adds 3 to r0 (always 0) and stores the result in r1 addi r2,r0,5 ;adds 5 to r0 and stores the result in r2 add r3,r1,r2 ;adds the contents of r1 and r2, and stores the result in r3 halt ;stops execution
If that looks like shenanigans to you, have a quick look at the glossary of DLX assembly syntax.
For the most part, DLX assembly commands read like:
mylabel action [result destination],[argument 1],[argument 2]
Note that whitespace is important! Labels must be in the first column, assembler directives and opcodes in the second column, and arguments in the third column.
Save your program from your text editor with the extension .dls.
I saved mine as adding.dls.
Assembling your program
- Main article: dasm
Next, we're going to assemble the program into an executable file, using "dasm.jar".
Make sure dasm.jar is in the same folder as your .dls file.
Open command prompt, and navigate to the folder that your .dls file and dasm.jar are located in using cd.
Then, use the following command to assemble your code:
java -jar dasm.jar adding.dls -a
As long as all your program fits inside the first bank of memory, you can assemble all of your programs using the above command, just changing the name of the source file.
If all goes well, you'll now have an executable file named adding.dlx in your folder.
Executing your program
- Main article: Debugger
Go to the homepage at http://vo-em.com and click "load .dlx" from the debugger. Navigate to your DLX file and load it into the debugger.
To begin execution, click the play button under the screen (|>)
If you're not already at the CPU debugger page, press 1 to bring it up. You should see that r3 now contains the value '8' like you'd expect.
If so, congratulations! You've added 3 and 5!
Try reloading the program and stepping through it with ||> to see the execution in slow motion.
Feel free to try the challenge section. Otherwise, on to the next tutorial!
Can you make the program store the result somewhere in RAM? Hint: You'll need a save operation.
Use the memory debugger on page 3 to see if you've succeeded!
Don't be too cut up if you can't get it working - we'll cover this in tutorial A3.