Skip to main content

Emulator Basics - Running Code

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.

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.

Other Posts in this Series

Comments

Popular posts from this blog

Am I Jonesing for the Internet?

I’m feeling a little agitated and jittery today. My internet access is down due to some nasty snow and wind. Are the two related? They might be. I know I’m certainly missing my twitter friends and feeling less in touch with the world. How long is this weather going to hold? I can’t look that up. Sure, I could pull out a radio and listen in, if I had one. I might somewhere, but I’m at the mercy of the broadcaster to decide when to report the weather and how much of it to report. Some argue that internet access should be a basic human right. Does this point of view hold water? I suppose it could be argued that since the internet allows us to draw together into a larger community that it is an essential part of improving the human condition. Its use in political organizing and to connect dissidents in repressive regimes can certainly help make the case for it as a basic human right. Is the jitteriness really from not having the internet? My doctor did just increase my dose of modafi

What Kind of Games?

I started programming when I was young, with the hopes of writing video games. I think a lot of kids start that way. When you like something, or someone, you try to emulate what you’re seeing. But how has that early dream turned out? They tell writers to write what they know. It’s good advice. How can you write about life in the Serengeti without have someone to give you a first hand account or having been there yourself? You can always use your imagination, and that’s all you can really do when writing fantasy or science fiction. It works for writing video games. How can you expect to write a genre you don’t immerse yourself in? These days I spend most of my gaming time playing casual games. I’m busy doing other things, and don’t want to spend long stretches just sitting at the console or computer. Recently I read an article about the kind of video games the most people tend to flock to. Typically they’re games that are relatively simple and involve sorting things in some way. It

Piet - an esoteric programming language

There’s a certain group of programmers out there that like to come up with programming languages just for the fun of it. Some of them have profanity as their names , and some are based on internet memes . Whatever the case may be, some individual out there enjoyed thinking up the language, and many of these languages are actually useable. One esoteric language that stands out, for me, at least, is Piet , created by David Morgan-Mar. Based on the idea of making programs that look like abstract art, Piet allows the programmer to express their software in the form of coloured blocks. Numbers are represented by blocks of pixels containing a pixel count equal to the number itself. Operations are performed by changes in hue or darkness. As an example, here is a Piet program I wrote to output the string “Hello World”. This image is in fact the entirety of the program, and can be run in any of the Piet interpreters out there. Other examples of Hello World programs are available on David’s si