Shop OBEX P1 Docs P2 Docs Learn Events
Variable Space & Lookup Table — Parallax Forums

Variable Space & Lookup Table

YendorYendor Posts: 288
edited 2006-10-01 20:59 in General Discussion
Welp, I just hit 19 Variables on the SX28·and wanted to add some more functionality.

Referencing the help file on Variables, I'm seeing:

attachment.php?attachmentid=73947
Looking at my code·I have:
  • 6 Word Variables = 12 Bytes
  • 7 Byte Variables
  • 3 element Array of type Byte
  • 3 I/O Ports
So, as far as from what I've read from SX/B RAM Banking Scheme, I'm understanding that now I would need to use arrays and an alias for any other variables.·

1.· How do I determine how much variable space do I have left?
Mapping out the remaining space, I was curious·how are I/O ports part of the variable mapping, and how much actual variable space I have left:
It looks like I have the following available:
  • 1X5
  • 1X1 (using 3 elements of the 1X4)
  • 6X16· > Is this·where the max 16 comes from in the table?

2.· In the case of aliasing,· shouldn't they function as a regular variable?
myValue Word
index VAR byte(3) 
i VAR index(0) 
j VAR index(1) 
k VAR index(2)
 
j = 3
Lookup j, CON1, CON2, CON3, CON4, CON5, CON6, myValue

When I comple this, I get a 'BYTE VARIABLE EXPECTED: "j"' error.
·3.· Within my program, have a a incrementing counter.·· Based on·that counter, I want to lookup a position for a predefined·address label, and use it in the read statement later on in my programm.
I initially tried·using the WDATA statement, as in

WDATA LABEL1, LABEL2, LABEL3, LABEL4, LABEL5
The compiler didn't like it.· Should this work?

In finding an alternative, I used a real byte instead of an array, on #2 above,

myValue VAR Word
i VAR Byte
 
i = 3
LOOKUP i, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, myValue

The compiler liked it better, but still complains with the following:
·Warning 73, Pass 2: Mulit-byte instruction following skip instruction.·
Looking at the assembly shows that it looks like it's doing what I want.· Is there any concern?

Is there another alternative, to do what I want to do other than multiple if-then's?· Branching won't work since I don't actually want to execute the code at the addresses.


Thanks!

Rodney


·
398 x 124 - 5K

Comments

  • BeanBean Posts: 8,129
    edited 2006-10-01 13:44
    Rodney,

    1) I/O port pins don't count as variables at all. The SX28 RAM is broken into 16 byte "banks". These "banks" are NOT continuous. So an array cannot extend from one "bank" to the next". So if you were to·declare arrays of 9 bytes, the 7th one would fail. In short ALWAYS declare arrays largest first, smallest last.

    2) Yes, many commands will work with aliased array elements. LOOKUP and LOOKDOWN are two that do NOT support array elements YET (hint hint). There are some others too, for instance an array element cannot be used as a FOR-NEXT control variable.

    3) Rodney, you always seem to think of things I never have. I would have never guessed that someone would want to put labels in a WDATA command. For now, I would use the multiple IF-THEN statement. I'll look into allowing this.

    Bean.






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-01 16:14
    The other option is to use a subroutine to access ram.
    I made a SX/B library file of my assembly routines.
    These let you read/write both ram and the special config registers
    and also allow rambank0 access, all via SX/B.
    The file with extension LB (for Library Basic) is 'load'ed into the main SX/B program.
    It contains the library·subroutines.

    regards peter

    Post Edited (Peter Verkaik) : 10/1/2006 4:50:42 PM GMT
  • YendorYendor Posts: 288
    edited 2006-10-01 20:59
    Wow, wasn't expecting a response on Sunday - Thanks!



    Lists of Lists
    I appreciate·you looking into·#3, Bean.· It looks like it's almost there anyway, looking at the assembly.

    It just seemed logical to me to organize data statements with variable information this way in my application.

    For example:
    List1: 
    Data #bytes,data1, data2, data3, data4 
    
    
    List2: 
    Data #bytes,data1, data2, data3, data4, data5, data6 
    
    
    List3: 
    Data #bytes, data1, data2 
    
    'Then have a list of lists: 
    Lists: 
    Data #Lists, List1, List2, List3
    


    This is kinda like a multidimentional array of constants.· If the user selects 1, they will access the data from list1; 2, for list2, etc.

    Still not clear on Avail. ROM/RAM Space:
    So, how do we find out how much EEPROM space is left?· In the SX-Key IDE, under·Device Option in the E2FLASH window?··I'm still not sure how much variable space I have with the Arrays. Was I correct on what I have left?· I caught the large to small on the help file on the Array's, but·I'm not sure why 7 of 9·would fail in my example.

    Peter, thanks so much for the files.··I was a little dissapointed that·I'd be two variables short when I go to the SX/48 board, and was affraid my app may not have the flexibility I initiall desired on the SX/28,·but now I have renewed enthusiam, once again!· I'm still working on·enhancing what I'm doing, but as soon as I need that one·extra variable, that I can't use w/ an array alias,·I'll be sure to dig in!

    Rodney

    Post Edited (Yendor) : 10/2/2006 4:08:31 AM GMT
Sign In or Register to comment.