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

Losing a loved one, as an atheist

When I was around 11 or 12, I started to question the received wisdom that there was a deity. I came to the conclusion that all signs pointed to no. Do I outright, unequivocally and without reservation deny the existence of such an entity? No. However, I don’t see it as a likely scenario, and until I’m presented with hard evidence, I have enough reason to say that there isn’t. Some people take comfort in their religious beliefs, especially their belief in an afterlife. I have no interest in an afterlife, either for myself of my loved ones. In the past five years I’ve lost both my grandmother and mother, both of whom I loved dearly. No amount of belief in an afterlife would soothe my pain. I mourn at the fact that they are lost from my life, right here, right now. I imagine it’s the same even for those who believe that the dead pass on to somewhere else. You can’t escape the fact that their tangible presence is forever gone from your life. Unless you believe in ghosts, but that’s a ...

Living with Bipolar Disorder

Feeling down when something bad happens is normal. Feeling elated when something good happens is great. Bipolar disorder is neither. Previously referred to as manic depressive disorder, bipolar disorder consists of mood episodes ranging from deep, dark depression to the sense of invincibility and superiority that is characteristic of a manic phase. It disrupts the lives of those who suffer from it and all those around them. Luckily, however, with the right course of treatment it can be kept under control. Bipolar disorder has been found to be linked genetically and physiologically to schizophrenia. A person suffering from bipolar disorder can experience the same sort of hallucinations and delusions as someone with schizophrenia. Both have a genetic component, with a number of genes interacting to create a pre-disposition to these disorders. The families of those afflicted often include others with one of these disorders, mood disorders or alcoholism. Depression is a common symptom ...

Another post

It's been over a week since I've posted here, and I apologize to my loyal readers who have probably all headed to the hills. Twitter has been keeping me distracted, while my bipolar disorder and newly-diagnosed ADHD have left me feeling less than effective. It's hard to push yourself to try to succeed when you feel you've been so far from stellar that bothering with anything is a waste of time. But things are picking up. I'm on new medication, I have great friends, an incredibly supportive wife and a window into new techniques to help keep my problems in check. There's definitely a gleam of hope where a short while ago there was none. I'd love to find employment, but my chosen field of expertise, software development, seems to be yielding little, if any, job prospects in the area. I can always cast out a wider net in my search, since so far I've only looked at Nova Scotia. However New Brunswick and PEI are both a stone's throw away. PEI is apparently...