'how can i convert my swap function from C to mips32 code?
Ihave this function:
void swap(int i, int j){
int temp=v[i];
v[i]=v[j];
v[j]=temp;
}
where i and j are elements from a global array v[]
I have written this code in mips thus far but the array stays the same and nothing changes:
swap: # swap entry point
sll $t3,$a0,2
sll $t4,$a1,2
add $t3,$gp,$t3
add $t4,$gp,$t4
lw $t0,0($t3) #t0=v[i]
lw $t1,0($t4) #t1=v[j]
sw $t0,0($t4)
sw $t1,0($t3)
jr $ra # return to caller
where $a0=i and $a0=j
Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
