FOR SETEP is faster calculating parameters than using variables

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

FOR SETEP is faster calculating parameters than using variables

Post by bola_dor »

:shock:
I was playng arroud drawing circles an elipses and found that using
FOR A=0 TO 2*PI STEP 2*PI/L
Is faster than using variables replacing both the counter end and the STEP paremeter with precalculated variables. it was almost a seccond from 77s but it means several bytes less too
thet wasn´t the same when I replaced L wit the elpse perimeter formula that includes SQR and **.
I guess PI is faster to retrieve than any variable but I thought division and multiplication would cost much more frames...
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
Flatulentia
Posts: 93
Joined: Sun May 14, 2023 3:58 pm
Location: Cambridgeshire, UK

Re: FOR SETEP is faster calculating parameters than using variables

Post by Flatulentia »

I'm very rusty when it comes to programming my ZX81, but isn't this something to do with the use of PI requiring less bytes to be read?

I seem to remember using various incantations of PI (eg, PI-PI instead of 0) for space saving on a 1K ZX81 many years ago.
ZX81 with ZiLOG Z84 CMOS Z80, 32KB battery-backed Toshiba 55257 SRAM with charge status LED, Wilf's "Why Wait?" mod and switch-mode 5V regulator. 50/60Hz mode switch, composite video output with Zigg's back porch mod and 1080p60 HDMI output.
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: FOR SETEP is faster calculating parameters than using variables

Post by 1024MAK »

PI is definitely useful for saving space. This, along with many other methods is covered in a useful tips topic.

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.
User avatar
Paul
Posts: 1517
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: FOR SETEP is faster calculating parameters than using variables

Post by Paul »

Frequent used variables have to be the first variables defined. That makes finding them much quicker.
In theory, there is no difference between theory and practice. But, in practice, there is.
Post Reply