No. You want to pass the address where the data to write are in r1
, not the value itself.
Therefore r1
should be set to just <address-of-array> + <index>
, i.e.:
ldr r4, =array /*Set r4 to the address of array*/
add r1, r3, r4 /*Add offset to point to array item */
It crashed for you, because you tried to read from memory at an invalid address -- the value of the array item. You were reading a word (ldr r5, [r3,r4]
), not byte, from the array at index r3
, then trying to read another word (not byte) from that address.
It is not relevant in this case, but just for reference, you would use lrdb
to read a single byte.
Also the "invalid address" above might be both that it is undefined and falls outside of any mapped region, but also that it is improperly aligned. The ARM architecture disallows reading a word, e.g. a 32 bit value, from address not aligned at those 32-bits (4 bytes). For r3 == 1
in the second iteration, this wouldn't apply (assuming array
would start on a 32-bit boundary).