Picaxe arrays

moxhamj

New Member
This is a question tagged on to the thread about radio door networks. I am wondering if there is picaxe code that can use arrays where the address of the array is a variable? Specifically, read b0 to b13 into an array such that each one can be accessed with a variable in a loop.

The problem is due to code space. The code needs to check each one of b0 to b13 and compare with another variable value. A simple code would be if b0=variable then, if b1=variable then... but this takes up space.

I'm thinking of whether b0 to b13 are stored in locations that can be accessed with peek and poke (on smaller chips like an 08M 14M). One could then read in b0 to b13 with serin and then set up a loop that peeks these values and pokes to new scratchpad locations, eg by adding 16. This would only be a few lines if in a for/next loop and would free up b0-13 to use in the code. Then the new locations could be pointed to in a new for/next loop and checked against values, and again this is less lines of code than checking each location seperately.

Is this a way to set up pseudo arrays? Bigger chips like the 28X have the ptr code but is there a way of doing this with smaller chips?
 

hippy

Ex-Staff (retired)
Yes ...

- Symbol B0_ADR = $32
-
- For b12 = 0 To 11
--- b13 = b12 + B0_ADR
--- Peek b13,b13
--- SerTxd( "b", #b12, " = ", #b13, CR, LF )
- Next

This is quite handy for moving bX variables to other SFR and back again when running out of variables in routines. I think I've got the address of b0 as $32 right, haven't tested the code.
 
Top