Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Sorting Routine for Signed Integers - Error 126: Out of Variable Space — Parallax Forums

BS2 Sorting Routine for Signed Integers - Error 126: Out of Variable Space

ATSATS Posts: 4
edited 2011-05-10 15:21 in BASIC Stamp
Hello all,

How can I increase my variable space for the BS2?

I am generating a 10-element pseudorandom signed integer array and sorting it in both ascending and descending orders. Therefore, I am required to create two 10-index Word variable arrays, for a total of at least 40 bytes! I am not able to "simplify" this, nor am I permitted to use any "recyclable" temp variables in my program. I simply need to know how one can increase variable space using the BS2 + pBASIC 2.5.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-10 06:52
    You can't. There is no way to do it. There are 13 words. That's all that exist. These can be used as words (13), bytes (26), nibbles (52), individual bits (104) and some combinations of those.

    It is possible to store constant data arrays in EEPROM using the DATA statement and using the READ and WRITE statements to manipulate the values (read the manual for details). The problem is that you're limited in how many times you can change a location. Once you get around 100000 times, the memory location may wear out. It eventually can't be changed any more and the bits get stuck at one. Sorts involve a lot of changing of values in the data array. You can easily exceed this limit with a few worst case sorts, so that's not really a solution for you.
  • ATSATS Posts: 4
    edited 2011-05-10 07:10
    Thank you, Mike.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-05-10 10:59
    ATS wrote: »
    Hello all, How can I increase my variable space for the BS2?

    I am generating a 10-element pseudorandom signed integer array and sorting it in both ascending and descending orders. Therefore, I am required to create two 10-index Word variable arrays, for a total of at least 40 bytes! I am not able to "simplify" this, nor am I permitted to use any "recyclable" temp variables in my program. I simply need to know how one can increase variable space using the BS2 + pBASIC 2.5.

    Perhaps I am not understanding the reason why you need both arrays? If you sort the array in ascending order, you can simply reverse reference the index elements for descending. So if you sort the array, referencing the indexes from lowest to highest gives you ascending and referencing them in reverse gives you descending. Would this work for you?

    Another option is a BASIC Stamp with Scratch Pad RAM, such as the BS2p24 which has 126 bytes of RAM available which could be used for this type of thing.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-05-10 15:21
    Another way to do this is to use a table of 4-bit pointers in RAM, and sort those instead of the actual data. That is, the 10 signed 16 bit data words go into the EEPROM in whatever order they are produced, and an array of 10 NIBbles in RAM rank them.
Sign In or Register to comment.