Shop OBEX P1 Docs P2 Docs Learn Events
Lookup tables in VAR blocks? — Parallax Forums

Lookup tables in VAR blocks?

Jack BuffingtonJack Buffington Posts: 115
edited 2010-04-02 21:44 in Propeller 1
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.
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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-04-02 19:06
    You can pass the hub address of a DAT block to an assembly cog the same as you do a VAR array. For your "other variables" that you need to pass, just tack them onto the end of the DAT block, initialized to zeroes, instead of declaring them as VARs.

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-04-02 20:45
    If you are providing a list of variables to the the assembly routine you can just add the address of the DAT table to the variable list.· Something like this:
    DAT
    lookupTable long        1,2,3,4,5,6,7,8,9,10 
     
    VAR
    long    varlist[noparse][[/noparse]3]
      
    PUB start(arg1, arg2) 
      varlist[noparse][[/noparse]0] := arg1
      varlist[noparse][[/noparse]1] := arg2
      varlist[noparse][[/noparse]2] := @lookupTable
      cognew(@PmyAssemblyStart,@varlist)   
     
    
  • mparkmpark Posts: 1,305
    edited 2010-04-02 21:00
    Your other post did get replies. Did you even look?
  • Jack BuffingtonJack Buffington Posts: 115
    edited 2010-04-02 21:30
    Got it! Thanks!

    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  0
    
    

    Post Edited (Jack Buffington) : 4/2/2010 9:36:37 PM GMT
  • Jack BuffingtonJack Buffington Posts: 115
    edited 2010-04-02 21:36
    mpark,

    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.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-04-02 21:44
    You can reset the cog address pointer using the ORG statement. That way each distinct block of assembly code in a DAT section has its own start address, viz:

    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
Sign In or Register to comment.