ZX Spectrum – Memory saving tips used

You will see a lot of these in some listings and, if your brain is as addled as mine is trying to remember all of these tricks from back in the day, here’s a handy reminder.

VAL “number” – Whilst it can make a listing look unwieldy, it was necessary back in the day. Using VAL with an integer will always be three bytes shorter than that integer used directly.

Replacing integers with built-in commands that generated a value, like the following examples:

x = SGN PI (aka x=1)
x = NOT SGN PI (aka x=0)
x = PI-PI (aka x=0)
x = PI/PI (aka x=1)
x = COS PI (aka x=-1)
x = INT EXP SGN PI (aka x=2)
x = INT PI (aka x=3)

The above examples saved you a few bytes compared to using the standard LET X=1 or LET X=0 commands due to the way that ZX BASIC used tokenized keywords. I found the following on StackExchange which explains why this was done in Spectrum BASIC far better than I could.

Back to ZX Spectrum – BASIC