Swapping two elements in an array in MIPS assembly -
i'm trying learns mips isa. if want function in mips:
a[2*i]=a[2*k+j];
how go this? appreciate other content can read, i.e links can read on how solve kind of problem.
we can break down 2 parts:
- calculate addresses of a[2*i] , a[2*k+j]
- assign value @ second address memory @ first address
i'm going address (ahem) #1.
to calculate address of array element, need know 3 things:
- the address of start of array
- the index of element want
- the size of array elements
i assume know how compute, or know, #1 & #3. leaves #2, involves simple arithmetic. (since haven't indicated how i, j & k represented, can't there).
the final step, then, multiply index size of array element; gives offset of desired element start of array. add address of start of array, , have element's address.
p.s. code you're translating doesn't swap 2 elements; copies 1 on other.
Comments
Post a Comment