I'm currently learning about basic assembly language via RISC-V, and I'm slightly confused on valid ways to loop through an array.
If we're given a0 as a pointer to an integer array, would this suffice to move to the next element?
If I would want to modify the actual value of the element at the location as well, can I simply use sw?
I also know using slli/srli also allows you to shift, can anyone explain that concept?
Thank you!
The basic pattern for traversing an array (with n elements) is this:
Y = X + n * 4
) with shift and add instructionslw
to load the word from the address that is present in X) and do something with that array elementadd
instructionRegarding modification: You modify the loaded array element in a register and then you can store the new register value back into your array with sw
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.