I can't seem to figure this out, the bug in this swap procedure in C is the *temp is a pointer to a pointer, and I seem to have written the wrong version of it in Mips. I have two problems, one, I don't know what is wrong with this swap procedure, and two, I don't know how to properly write it in Mips. Any suggestions guys?
Code:
Problem:
void swap (int *px, int *py) {
int *temp;
*temp = *px;
*px = *py;
*py = *temp;
}
Correct swap:
void swap (int *px, int *py) {
int temp;
temp = *px;
*px = *py;
*py = temp;
}
This is my buggy version of swap, which unfortunately, isn't buggy. The directions in my lab said that "cannot use $t0 to hold temp." So how do I write this?
My attempt:
Code:
swap:
addi $sp, $sp, -8
sw $ra, 4($sp)
sw $s0, 0($sp)
lw $t0, 0($a1)
addi $t3, $v0, 0 #ptr *temp
add $s0, $t0, 0 #i'm so lost lol
move $a0, $a1
move $a1, $s0
lw $s0, 0($sp)
lw $ra, 4($sp)
addi $sp, $sp, 8
jr $ra