Anders Tornblad

All about the code

Label archive for z80

"Hello, World!" in ZX Spectrum machine code

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

CHANOPEN equ 5633 PRINT equ 8252 ld a, 2 ; 3E 02 call CHANOPEN ; CD 01 16 ld de, text ; 11 xx xx ld bc, textend-text ; 01 0E jp PRINT ; 3C 20 text defb 'Hello, World!' defb 13 textend equ $

This piece of code calls two functions 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.

I think I need to add Z80 assembler definitions to my code formatting script...

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