Now that I've covered the instruction set, it's time to talk about the assembler and running your assembly programs. The assembler is available as a standalone tool, but is also bundled into the emulator, allowing you to go directly from assembly to running your code in one step.
Previous Posts
The following posts cover the instruction set for the emulator. They can serve as a good resource once you decide to start writing code of your own.
Setup
If you haven't already, clone https://github.com/skwirl42/robco-processor into the directory of your choice. At the moment only the macOS port is fully maintained, so the instructions will be focused on using the project on macOS.
Linux
I have yet to port it to linux, but that is planned. If you would like to work on it, there's a task available on the repository. Ideally, this should be straightforward. If you plan to work on the linux port, please let me know! It appears that homebrew is also available for linux, so that might be a good place to start.
Prerequisites
Make sure you have the latest XCode installed, along with its command line tools.
- Install the latest CMake from https://cmake.org/download/
- Install homebrew from https://brew.sh
- Use homebrew to install boost, SDL2, and SDL2_image
- $ brew install boost sdl2 sdl2_image
IDE
I use Visual Studio Code as my IDE, with the CMake extension installed, but if you're more comfortable with XCode projects, or Makefiles, configure CMake to use those project generators.
But CMake is ****!
No, it really isn't. I enjoyed working with it, but if you get the chance to spend many, many hours making your own project using something else, then by all means, go for it. But this project uses CMake.
Build It
At the moment you'll be looking to build the robcoterm target. If you went the Visual Studio Code direction with no changes in setup, it should have built the executable into <project dir>/build/Debug/robcoterm.
Running Code
We'll start with a simple example program, the good old standard Hello World:
1 2 3 4 5 6 7 8 9 10 11 12 13 | .include "syscall.asm" .data HELLO_WORLD "Hello, world!\n" ; .data specifies data to be store in the executable ; In this case, it's the string to print start: pushiw HELLO_WORLD ; Put the address of the HELLO_WORLD string onto the stack pullx ; Pull the top value on the stack into the X register print_string: syscall PRINT ; Call the system's PRINT routine (takes a null-terminated string ; pointed at by X, and prints it to the screen) b print_string ; branch back to the label print_string to continuously write ; "Hello, world!\n" to the screen |
For now, just copy that into a file named hello_world.asm, and run the following, replacing values in angle brackets to match the appropriate paths on your system:
$ <robocoterm> -I <project dir>/samples -S <hello_world.asm>
If all went well, you should have something like the following appear:
There, you've run your first program in the emulator!Samples
You can find more to run in the samples directory inside the project. There are also files meant to be .included in that directory, and won't produce any useful output if run directly. echo_getstring.asm and graphics_test.asm can serve as a good jumping off points for inputting and outputting text, or working with graphics, respectively.
Next
Next time I'll go over some useful system calls so you can try out some more complex patterns.
Comments