3 ms·
I probably wouldn't want to do automatic striping of arrays of structures, because it'd only make sense in some circumstances, but it'd be trivial to add logic
by david-given 9y ago
I probably wouldn't want to do automatic striping of arrays of structures, because it'd only make sense in some circumstances, but it'd be trivial to add logic to the code generator to use indexed addressing modes --- you'd need to check to see if the thing being indexed was an array with bounds small enough to be indexed with an 8-bit variable.
<thinking out loud follows>
...that would produce something like:
lda index
rol a # scale for 16-bit values
tax
lda address+0, x # read low byte
ldy address+1, x # read high byte
== 11 bytes (assuming index and address weren't in zero page). But of course if I were reading a 16-bit value, I'd probably be wanting to dereference it as a pointer or do arithmetic on it, so I wouldn't want to read it into registers all at once --- the 6502 likes streaming maths through the accumulator a byte at a time.
Something like 'result = array1[index] + array2[index]' would end up:
lda index
rol a
tax
clc
lda array1+0, x
adc array2+0, x
sta result+0
lda array1+1, x
adc array2+1, x
sta result+1
== 24 bytes!
(When I was about 10, the 6502's lack of 16-bit arithmetic made me very sad. It still does, but it did then, too.)
- spc476 9y agoYou could always incorporate SWEET16 (https://en.wikipedia.org/wiki/SWEET16 https://en.wikipedia.org/wiki/SWEET16) to support 16 bit math.