Number of variables/program lines

cpedw

Senior Member
I'm quite new to PICAXE and enjoying it a lot. In tinkering, I have found that the balance (I presume it's a tradeoff) between program space and number of variables is too much for program, not enough for variables. I'm using an 18X.
I expect that it depends on just what you are trying to do but I wonder if this is the general experience or perhaps my programming approach needs to change.
Any others' experience and advice will be welcome.
Thanks,
Derek.
 

Technical

Technical Support
Staff member
Look up the peek and poke commands, these will give you a larger array of RAM space if you need it.
 

hippy

Technical Support
Staff member
The trick Technical suggest allows variables to be re-used. One use is to give a number of subroutines their own unique variables. In the following, each subroutine gets its own b0, b1 and b2 variables for its own use. Each subroutine can can update those without affecting any other subroutine's b0, b1 or b2 variables ...

- MainLoop:
- GOSUB Sub1
- GOSUB Sub2
- GOSUB Sub3
- GOTO MainLoop
-
- Sub1:
- PEEK $50,b0
- PEEK $51,b1
- PEEK $52,b2
- <i>Sub1 code here </i>
- POKE $50,b0
- POKE $51,b1
- POKE $52,b2
- RETURN
-
- Sub2:
- PEEK $60,b0
- PEEK $61,b1
- PEEK $62,b2
- <i>Sub2 code here </i>
- POKE $60,b0
- POKE $61,b1
- POKE $62,b2
- RETURN
-
- Sub3:
- PEEK $70,b0
- PEEK $71,b1
- PEEK $72,b2
- <i>Sub3 main code here </i>
- POKE $70,b0
- POKE $71,b1
- POKE $72,b2
- RETURN

Here's another trick which can be used when a FOR index variable is simply a counter and not used within the FOR..NEXT loop ...

- FOR b0 = 1 TO 10
- POKE $50,b0
- :
- <i>b0 can be used here without worry </i>
- :
- PEEK $50,b0
- NEXT
 
Top