Given:
.data
arr: .word 2,5,1,3,4
len: .word 5
sum: .word 0
How would I access each word in “arr” such as 2, 3 and 4?
Eventually, what I would like to do is find a sum of all of the values in “arr”, but I’m having difficulty iterating through “arr”.
Thank you for your time!
Additional Info:
- I’m using eduMIPS64
First load the address of the array into a register, then you can access the items with a constant offset. (Your assembler might support constructs such as
lw $t0, arr+12as convenience shorthand for this. See your manual.) For iteration, either increment the address register, or add another register containing the offset. Be sure to account for item sizes. Folling example is for 32 bit mips, adjust as necessary for 64 bit:(note these sample loops do not handle zero length array, add check if necessary)