BS2 Sorting Routine for Signed Integers - Error 126: Out of Variable Space
ATS
Posts: 4
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.
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
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.
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.