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:

  1. calculate addresses of a[2*i] , a[2*k+j]
  2. assign value @ second address memory @ first address

i'm going address (ahem) #1.

to calculate address of array element, need know 3 things:

  1. the address of start of array
  2. the index of element want
  3. 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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -