Hello World! – Spectrum Assembly Tutorial 01

I figured it was about time to delve into the fantastical world of the Speccy when it comes to teaching some basic assembly language for the 8 bit Micros. I sincerely hope that through my work that you, the reader, become as enthusiastic for these systems as I have become. This is going to be a bit of a whistle-stop tour, nothing is explained elaborately as I want you to first get the confidence in using the environment and seeing something appear on Screen.

Setting Up the Development Environment

I have been using the Spin Spectrum Emulator for development. Spin contains a built in assembler so there is no additional set-up required once the program is installed. You can find Spin at the official website. Once you have unzipped the files to a location of your choice open the Program executable (called ZXSpin.exe).

You will be greeted with the following screen

As mentioned previously, this rather attractive emulator contains a built-in assembler. to access this click the Tools menu option and select the Z80 Assembler. You should now be presented with the Assembler screen. This is the screen we will be spending our time in.

A Simple Hello World Program

As is traditional in programming circles, I have decided to being with printing Hello World on the screen.

The first line of code tells the Spectrum where our code is going to be stored in memory. In this case it is the address of 8000

Next we create a function called PrintChar this will use the accumulator to print a character to the screen. In order to do this we first need to open a channel to the screen. This is done by loading the accumulator with 2 and then calling &1601.

1601 is the address instruction to tell the Spectrum that you want to open a channel. Stream 2 in the Spectrum is the top part of the screen. Indicated below.

Anything below the Sinclair Research Statement which appears when you initially boot the Spectrum is considered the bottom of the screen.

Now that our channel is open, we use the RST 16 command to print the character.

We use a lot of Pushes and Pops in the stack to ensure that none of the registers are changed during this function.

We then create a PrintString function which uses the PrintChar function and loads the message in, passing it through character by character.

The main body of the program then calls the PrintString method and I place a halt command in order for the program to wait for a few cycles.

Running the Program in Spin

To run an assembly language in the Spinf emulator click the File menu and select Assemble, don’t worry about the dialogue box which appears, press the ok button. This begins the process of assembling your program. Once this has completed without any errors, you will be able to run the program by clicking the Program menu option and Run.

You should see the following appear on your screen.

Full Program Listing

Congratulations you have setup your development environment and coded your first message onscreen!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s