what is this code doing exactly?

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Crayon21
Posts: 355
Joined: Sun Nov 04, 2018 2:33 am

what is this code doing exactly?

Post by Crayon21 »

I just typed in the 1k version of pumpkin for the zx81 and have a question:
I noticed that this version is using a lot of VAL statements but where is the information coming from
Logic would dictate that the CPU would be getting the info from data statements. Obviously sinclair basic lacks this (until the speccy anyway) so how exactly does this code function? What's happening here. can someone break this down step by step?

https://archive.org/details/syncmagazin ... ew=theater
page 11
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
SafePit
Posts: 45
Joined: Mon Feb 20, 2012 7:06 pm
Location: Boise, ID
Contact:

Re: what is this code doing exactly?

Post by SafePit »

VAL interprets the string as a number or expression of a number (i.e. with functions and other calculations). Most of the use was to save memory (i.e. VAL "5" is the same as 5 but, but the first is 4 bytes and the second is 7 bytes). The most complicated is line 15, but you could remove the VAL and quotes and would run just fine, just may not fit in 1K.
Image
Image
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: what is this code doing exactly?

Post by 1024MAK »

SafePit wrote: Wed Mar 29, 2023 4:26 amMost of the use was to save memory (i.e. VAL "5" is the same as 5 but, but the first is 4 bytes and the second is 7 bytes).
This may sound strange, but it is due to the way that numbers are stored.

A numerical constant in the program, both the visible “text” is stored and also an internal floating point representation of it (which is hidden during listing) which takes up six bytes. Hence the number 5 takes up a total of seven bytes in memory. See also the chapter 27 in the manual here. The link to the full manual is here.

However numbers in between double quotes like “5” are treated as plain text. So VAL “5” uses four bytes (including one byte for the keyword ’token’ used for ‘VAL’.

The advantage as SafePit says, is by using VAL you save memory compared to not doing so. Very useful for a machine that only has 1K bytes of RAM. The downside is that using VAL in this way is slower.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply