Sunday 16 February 2020

ZX Spectrum Hello World! Assembler on Windows


1. Download the PASMO Z80 cross assembler.

2. Download and install the FUSE ZX Spectrum emulator

2. Save the following hello world! program to 'helloworld.txt'

; hello-world.z80
CHAN_OPEN   equ  5633
PRINT       equ  8252

            org  32512

            ld   a, 2                ; 3E 02
            call CHAN_OPEN           ; CD 01 16
            ld   de, text            ; 11 0E 7F
            ld   bc, textend-text    ; 01 0E 00
            jp   PRINT               ; C3 3C 20

text        defb 'Hello, World!'     ; 48 65 6C 6C 6F 2C 20 57
                                     ; 6F 72 6C 64 21
            defb 13                  ; 0D

textend     equ  $


3.  Compile the programme into a TAP file with basic loader
.\pasmo -1 --tapbas '..\Zx Spectrum\helloworld.txt' prog.tap >> debug.txt

-1 (digit 'one') Show debug info during both passes of assembly.

With the --tapbas option a tap file is generated with two parts: a Basic loader and a code block with the object code. The Basic loader does a CLEAR before the initial address of the code, loads the code, and executes it if a entry point is defined (see the END directive). That way you can directly launch the code in a emulator, or transfer it to a tape for use in a real Spectrum. 

4.  Open the prog.tap file in Fuse

Fuse will load the first part of the TAP file which is the basic loader programme

The Basic loader program
5. Run the assembler program by issuing the the command

RANDOMIZE  USR 32512

To type this on a spectrum 48K keyboard

type T to enter the RANDOMIZE command then
press Shift+Ctrl (to enter Extended keyboard mode - flashing E cursor) and type 'L' for USR
then type 32512 and press return to execute




* alternatively add the directive END 32512 to the end of the helloworld program and PASMO will include the basic command to run the assembly code automatically.