Lookup tables in VAR blocks?
I tacked this onto a previous topic but that topic was a little old and didn't get any replies...
Does anyone know how to initialize an array in a VAR block with pre-defined values. I need to pass the address of the lookup table to an assembly program. The lookup table will be followed by other variables that the assembly will need to reference. I can create a lookup table in a DAT block and then reference it from SPIN like this but that won't work for me directly.
I could do something like this but it sucks up another chunk of HUB RAM the same size as the lookup table. I'm tight on HUB RAM so I would prefer to not do that.
Is there some way to just initialize an array from within the VAR block. I'm not seeing anything in the propeller manual.
Does anyone know how to initialize an array in a VAR block with pre-defined values. I need to pass the address of the lookup table to an assembly program. The lookup table will be followed by other variables that the assembly will need to reference. I can create a lookup table in a DAT block and then reference it from SPIN like this but that won't work for me directly.
DAT
lookupTable long 1,2,3,4,5,6,7,8,9,10
PUB start
dira := $FFFFFFFF
repeat
outa := lookupTable
I could do something like this but it sucks up another chunk of HUB RAM the same size as the lookup table. I'm tight on HUB RAM so I would prefer to not do that.
DAT
lookupTable long 1,2,3,4,5,6,7,8,9,10
VAR
long theTable[noparse][[/noparse]10]
long count
PUB start
repeat count from 0 to 9
theTable[noparse][[/noparse]count] := lookupTable[noparse][[/noparse]count]
cognew(@PmyAssemblyStart,@theTable[noparse][[/noparse]0])
Is there some way to just initialize an array from within the VAR block. I'm not seeing anything in the propeller manual.

Comments
-Phil
One gotcha that I found was that the compiler seems to join multiple DAT sections into one address space so if I declare my variables in one file, I have to put my program in another file, which is what I normally do but for the sake of testing things out, I didn't.
For those of you searching for this same thing, here is the code that I wrote and tested:
In one file:
OBJ DISPLAY : "lookup02.spin" DAT temp3 long 0 ' this is here to keep things long aligned lookupTable long 1,2,3,4,5,6,7,8,9,10 otherVariable long 0 anotherTable long $FF[noparse][[/noparse]600] ' create a table PUB start otherVariable := 37 anotherTable[noparse][[/noparse]99] := 16 anotherTable[noparse][[/noparse]100] := 17 anotherTable[noparse][[/noparse]101] := 18 DISPLAY.Start(@lookupTable[noparse][[/noparse]0])In the other file:
PUB Start (address) cognew(@startDisplay,address) DAT startDisplay mov dira,#255 mov temp,par add temp,#40 ' skip over the 10 lookupTable variables add temp,#4 ' skip over otherVariable add temp,#400 ' skip over 100 variables in anotherTable rdbyte temp2,temp mov outa,temp2 ' output shows 17 AA jmp #AA temp long 0 temp2 long 0Post Edited (Jack Buffington) : 4/2/2010 9:36:37 PM GMT
I didn't see any e-mail notice from the forum so I posted again. In looking back now, I see that it was there after all. Sorry for the repost and thanks for your reply on the other thread.
DAT [s]temp3 long 0 ' this is here to keep things long aligned[/s] NOT NECESSARY lookupTable long 1,2,3,4,5,6,7,8,9,10 otherVariable long 0 anotherTable long $FF[noparse][[/noparse]600] ' create a table PUB start otherVariable := 37 anotherTable[noparse][[/noparse]99] := 16 anotherTable[noparse][[/noparse]100] := 17 anotherTable[noparse][[/noparse]101] := 18 cognew(@startDisplay,@lookupTable) DAT [b]org 0[/b] startDisplay mov dira,#255 mov temp,par add temp,#40 ' skip over the 10 lookupTable variables add temp,#4 ' skip over otherVariable add temp,#400 ' skip over 100 variables in anotherTable rdbyte temp2,temp mov outa,temp2 ' output shows 17 AA jmp #AA temp long 0 temp2 long 0-Phil