So, for the first program in assembly, we’re going to draw a block of colour. It’s very simple – just four lines of actual code – but it’ll test that your setup works, and then we can move more quickly after that.
Open your code editor, and create a new file – call it ‘First.z80‘, or ‘First.asm‘. The name, and file extension, could probably be anything, but z80 & asm are both commonly used, and good to describe what kind of file it is, and might be what instructs your syntax highlighter to treat the file as Z80 assembly. Now type the following into your file:
org 32768 ld a, 32 ld (22528), a ret END 32768
And that’s it, just six lines. Make sure the file has been saved.
Now you need to convert your code into something the Speccy will understand, by compiling it. In the case of Pasmo, this needs to be done on the command line, using the command:
pasmo --tapbas first.z80 first.tap
That will instruct Pasmo to compile your first.z80 file into first.tap, and create it as a TAP file which the Spectrum will understand. The option –tapbas tells Pasmo to create a BASIC loader for your code, which it will then use to load the code, and run it – all automatically. You might need to add the path to the location you installed Pasmo in, so it can be found. It’s best to run it from the folder your stored your code file though, so the TAP file is created there as well.
And finally you should be able to load the created file – first.tap – into your emulator to run it. And the result should look something like this:
“Wow!” you must be thinking, “It’s drawn a green square!” I promise you it’ll get more interesting soon!
If it doesn’t work, then the problem could be one of the following:
- You’ve mistyped the program – make sure it is exactly as shown above.
- Your compiler doesn’t understand it. The first four lines are very standard Z80 code, so there shouldn’t be a problem with those if it’s been typed correctly. The problem would most likely be with the last line – END 32768 – which is used to tell Pasmo to stop compiling, but more importantly where to start running the code from – in our case 32768 – as it matches the ‘org’ instruction in the first line. If you use a different compiler you might need to find out how it handles that.
- Your compiler can’t create a TAP file. Again, you’ll likely have to check your compiler’s documentation as to how to get this to work. If your compiler can create a TZX file that’s just a good, but if it can do neither then things could get difficult for you – and so is probably best that you try to find one that does.
Hopefully it all works though, and you’ve got that warm fuzzy feeling of success. In the next post I’ll describe what exactly it is that you wrote, and why it does what it does.