arrays
Lee Marshall
Posts: 106
hi, i want to be able to access the data in an array in asm, it seems the next logical step would be to find out how arrays are actually stored in memory, i assume it will be something like:
BASE ADDRESS: LENGTH OF ARRAY
BASE ADDRESS+1: ARRAY DATA 0
BASE ADDRESS+2: ARRAY DATA 1
etc...
so, how are arrays stored?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Propeller is the best micro!
srry if im sound a little unprofessional sometimes, im 15.
BASE ADDRESS: LENGTH OF ARRAY
BASE ADDRESS+1: ARRAY DATA 0
BASE ADDRESS+2: ARRAY DATA 1
etc...
so, how are arrays stored?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Propeller is the best micro!
srry if im sound a little unprofessional sometimes, im 15.
Comments
Arrays in Spin are fixed length, so the length doesn't have to be stored with the array.
Look at Ariba's (Andy's) response.
http://forums.parallax.com/forums/default.aspx?f=25&m=190445&g=190993#m190993
In this example the compiler will - through the declaration - know the length of the elements in "arr" (1, 2 or 4) and adjust the de-referencing accordingly. The above line - given that arr is declared as LONG - is absolutely equivalent to
The following example will give you all required information
Post Edited (deSilva) : 8/4/2007 8:44:56 AM GMT
translates to bytecode as ...
Whereas ...
should translate as ...
Post Edited (hippy) : 8/4/2007 2:59:17 PM GMT
But why? If I understand you correctly, this makes the SPIN interpreter more complex, with no major benefits in terms of array access.
Without that mechanism, the index would need pushing, the array's base address would need pushing, both added, and then the TOS would need to be popped and used as the address to actually load from. So this is very efficient, and not overly complicating for an interpreter.
It's not an efficient mechanism for constant array indexes, but that's down to the Spin compiler not optimising.
yes, and yes, thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Propeller is the best micro!
srry if im sound a little unprofessional sometimes, im 15.