Creating large array
Hello. Need help to create 256 bites long array.
I have BS2px. I get variable size too large when I try to declare array (array_name· VAR Bit (256)). I guess I am out of RAM space.
Is there any work around? I need serially shift 256 values (0 or 1), and I do not want to create several small arrays.
·
Thank you
I have BS2px. I get variable size too large when I try to declare array (array_name· VAR Bit (256)). I guess I am out of RAM space.
Is there any work around? I need serially shift 256 values (0 or 1), and I do not want to create several small arrays.
·
Thank you

Comments
myBitArray CON 64 ' starting SPRAM address for 32 byte array, can be anywhere pretty much index VAR Byte ' general counter param VAR Byte ' for passing value to subroutine(s) temp VAR param ' work var for subroutine(s) bitVal VAR Bit ' note that at reset/powerup, all vals should be 0, this writes 1s to each bit in the pseudo array Main: FOR index = 0 TO 255 ' loop through all 256 bits param = index ' which bit to get/set? bitVal = 1 ' set bit to 1 GOSUB PUT_BIT NEXT FOR index = 0 TO 255 param = index GOSUB GET_BIT ' now value of BIT #index is in bitVal DEBUG "Bit # ", DEC3 index, " = ", BIN1 bitVal, CLREOL, CR NEXT END ' some subroutines: ' set param to bit # to read (0 to 255) before calling routine ' returns bit value as 0 or 1 in bitVal GET_BIT: GET param >> 3 + myBitArray, temp ' get correct byte for this BIT (every 8 bits is a byte from the "stack") bitVal = temp.BIT0(param & $07) ' save correct bit for this byte into bitVal and return the value RETURN ' set param to bit # to set before calling routine ' set bitVal to value to set before calling routine PUT_BIT: GET param >> 3 + myBitArray, temp ' get correct byte for this BIT (every 8 bits is a byte from the "stack") temp.BIT0(param & $07) = bitVal ' set correct bit for this byte PUT param >> 3 + myBitArray, temp ' save it RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 7/24/2008 9:33:11 PM GMT
Also , if I need insert data to index 35-40, what is the procedure?
Thank you
Just set the index value, the desired bitval and it's done.
Each byte holds 8 bits. So when the param (the index) is shifted right 3 times, that divides the index by 8, resulting in byte 0-31. Then the routine gets the byte at that location in SPRAM. Then the lowest 3 bits of the param (the index bit desired) are used to set/get the bit WITHIN that byte that corresponds to the desired index.
e.g.
35 >> 3 (i.e. 35/8) = 4 --> working with byte index 4 (5th byte from bytes 0-31)
35 & $07 (i.e. 35//8) = 3 --> working with bit index 3 (4th bit of byte)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php