Can Of Code

Hello World in Spectrum assembly

I started this post originally in November 2013 but it ended up in the drafts pile. The idea then came back to me when I heard of the Spectrum ZA Vega IndieGoGo.

After a voyage into the roof I discovered a box of old electronics. Getting completely distracted from what I was supposed to be finding I took a peek inside the box to find a collection of Spectrum consoles and related accessories.

After digging around in the box I found this book:

Spectrum & Spectrum+ Assembly Language Course

Spectrum & Spectrum+ Assembly Language Course

 

I should explain that seeing such a book didn’t instil some sort of nostalgia. If i’m honest, it was before my time. The book did however spike my interest, perhaps I could see what life was like without the comfy luxuries of IDEs and managed languages.

 

Getting Started

It makes sense that the first step is to get the hardware setup. This gifted me with my first two issues:

– I have been reliable informed that none of the Spectrums in the roof actually work. Made in England!

– Even if they did work, I don’t have a TV that has a coax connector.

So my best bet was to try and find a Spectrum emulator. The search was both long and tiresome but I finally found an emulator that both worked and included a code editor.

Enter ZX Spin

ZX Spin

ZX Spin

You can get ZX Spin here. Unlike most emulators I found, this one works on Windows 8 and it runs straight out of its folder, no need to install anything.

 

Time for Hello World

So to print “Hello World” to the screen is a pretty simple command:

PRINT “Hello World”

The first gotcha here is that you would be inclined to type out “PRINT”  however the Spectrum keyboard worked in such a way that the “p” key would write “PRINT”

 

Spectrum Keyboard

Spectrum Keyboard

 

To type a string you need to surrond the string in quotation marks, nothing new there.  So to print out “Hello World” we would have to type:

P key  –  (Right Alt + P)  –   hello world – (Right Alt + P)

Hit enter and you should see:

 

hello-spectrum

 

Next time…

Next time I hope to create a reusable program using the tape emulation. I’m also intrigued by why they chose to use single key presses for commands? I assume it was a technical limitation?  Let me know in the comments if you have an insight.

Comments

  • Colin says:

    Hi,

    I had one of these machines at the time of the 80’s microcomputer boom in the UK. At the time, most American microcomputer systems were too expensive for many British families. The ZX Spectrum was released in March1982; two years before, Sinclair Research released the ZX80, the first mass market computer for less than 100 UKPounds. A year later, they released the ZX81. This had an improved display with floating point BASIC and was cheaper at 70UKP.

    Single-key command entry came about because the keyboards on the ZX80/81 were flat touchpad membranes, like the ones on some ATMs. In that context, it saved keystrokes and eased program entry. As you probably found, newbies ended up typing “PRINT RINT” the first few times until they got used to it.

    Single-key entry made less sense when the ZX Spectrum was released. It had a chicklet keyboard and many more keywords.

    Regarding reliability, mine failed in the first 12 months. I got a warranty swap; the replacement was a later issue PCB and was a reliable workhorse, it eventually received a proper keyboard and I had it for a few years afterwards.

    If you play with the emulator again, try it in 128K mode. The 128K Spectrum uses a fullscreen editor with normal command entry (ie, not single-key).

    Cheers,

    Colin.

    • josh says:

      Thanks for the info and the tip Colin, will be sure to give the 128k mode a go and hopefully make something more complicated

  • Damiano says:

    This emulator was actually very promising. Unfortunately, all its versions were buggy, including the supposedly stable 0.666, it had some weird audio issue. The one you are using (which is 0.7s experimental version) has an interruption bug. Not everyone can notice it, but if you run a game with background music and listen to it for a minute you will hear that it keeps disrupting a bit every now and then. Other versions didn’t have it, but they had their own bugs. So basically, none of them were perfect and it’s a shame authors of this could-be-awesome app just abandoned the project.

  • Peter Jones says:

    Hi,

    Any chance of scanning this book as it does not seem to be in the World of Spectrum collection. Only the cover shot.

    Thanks

    • josh says:

      Hi Peter

      I don’t have a scanner but I will see if I get my hands on one to get a scan of the cover.

      • Robs says:

        Hi Josh, is this a good book?

        I’d be happy to scan it for posterity and pay for the postage both ways.

        Send me an email if you’re up for it.

        Cheers 🙂 Robs

  • Sondar says:

    My previous comment was just an assembly language listing. How do we get that into your Spectrum to run it? See my next comment… 😉

    For playing round with Spectrum basic and machine code under Windows, I also generally use the BASin program (originally linked from the World of Spectrum archive, but I’ve found an updated version here: http://arda.kisafilm.org/blog/?page_id=848&lang=en)

    Download the program and familiarise yourself with how it works, and the display, so you can run the next example. BasinC also has a basic disassembler and debugger, so you can single step through the assembly language program.

  • Sondar says:

    THIS should now be the BASIC loader. Copy and paste it directly into the BasinC window, press Enter to move the cursor to a clear line, and enter RUN…

    10 DEF FN h(a$)=(CODE (a$)-48)-7*(a$>=”A”): REM Convert single hex digit
    20 DEF FN d(a$)=FN h(a$(1))*16+FN h(a$(2)): REM Convert 2 hex digits…
    30 RESTORE 4000
    40 LET addr=23296
    50 LET offset=0
    60 LET linenum=0
    70 READ h$
    80 IF LEN (h$)=0 THEN GO TO 3000
    90 LET l=LEN h$
    100 CLS
    110 PRINT “Line: “;4000+(linenum*10)
    120 PRINT
    130 FOR i=1 TO l STEP 2
    140 LET s$=h$(i TO i+1)
    150 LET dec=FN d(s$)
    160 LET d$=STR$ dec
    170 IF LEN d$<3 THEN LET d$=" "+d$
    180 IF LEN d$<3 THEN LET d$=" "+d$
    190 PRINT s$;" ";d$
    200 POKE addr+offset,dec: LET offset=offset+1
    210 NEXT i
    220 LET linenum=linenum+1
    230 GO TO 70

    3000 PRINT '"Finished loading data – press ENTER to call routine"
    3010 PAUSE 0: CLS
    3020 PRINT USR addr

    4000 DATA "21105B"
    4010 DATA "7E"
    4020 DATA "FE00"
    4030 DATA "2804"
    4040 DATA "D7"
    4050 DATA "23"
    4060 DATA "18F7"
    4070 DATA "012A00"
    4080 DATA "C9"
    4090 DATA "48656C6C6F2C20": REM "Hello, "
    4100 DATA "576F726C6421": REM "World!"
    4110 DATA "0D00"
    4120 DATA ""

  • Sondar says:

    As the spaces were messsed up, here’s the straight basic listing, without comments, addresses and numeric opcodes:

    ORG $5B00
    LD HL, message
    loop:
    LD A, (HL)
    CP 0
    JR Z, end
    RST 0x10
    INC HL
    JR loop
    end:
    LD BC,42
    RET
    message:
    DEFM ‘Hello, World!
    DEFB 13
    DEFB 0

  • Sondar says:

    I’m clearly having trouble with these replies!

    Here’s just the assembly language program; only opcodes. I’ll try post another reply with the full assembly listing (incl remarks) after this one…

    ORG $5B00

    LD HL, message
    loop:
    LD A, (HL)
    CP 0
    JR Z, end
    RST 0x10
    INC HL
    JR loop
    end:
    LD BC,42 ; Lo
    RET
    message:
    DEFM ‘Hello, World!’
    DEFB 13
    DEFB 0

  • tobo says:

    Can I just second that request to have this book scanned please?

    Failing that, sold perhaps?

    (worth a go, eh?)

    • josh says:

      The cover is not in best of condition but I would happy to scan this. I would also consider donating this to the community if I could find the right home for it.

  • Paul Land says:

    Is the book still available? I could Scan and or buy it so that everyone will be if it too.

    • josh says:

      Hi Paul,

      I have sent off the book to someone else to be scanned. I shall update this post as soon as that is available.

Leave a Reply

Your email address will not be published. Required fields are marked *