"Hello, World!" in ZX Spectrum machine code

#zx-spectrum #hello-world #retrocomputing #z80 #assembler

Written by Anders Marzi Tornblad

How to do "Hello, World!" in ZX Spectrum machine code.

; 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  $

This piece of code calls two subroutines in the original ZX Spectrum ROM. First it calls CHAN-OPEN which sets the current output channel to number 2 (normal screen output), and then it calls PRINT, which prints a string of characters to the selected channel. To print this on a ZX Printer, simply select channel 3 instead.

For more "Hello, World!" examples, go to the Hello World category.