Reputation: 1
im trying to make a simple program that copies a string soplas
to a .space directive called buffer
. im getting errors but im not sure where im going wrong, the beq
statement would be comparing the byte to the 0 ascii character since thats how strings are null terminated, right? copy is called using jal, hence the jr $ra
in the done subroutine
copy:
lb $t1, soplas($t0)
nop
sb $t1, buffer($t0)
nop
addi $t0, $t0,1
beq $t1, 0x00, done
j copy
nop
nop
done:
jr $ra
nop
nop
Upvotes: 0
Views: 89
Reputation: 26666
Let's say your C code would look like this:
void copy() {
int i = 0; // start i at 0 to work with soplas[0]/buffer[0]
while (true) {
char ch = soplas[i];
buffer[i] = ch;
i++;
if (ch == '\0') break;
}
}
Can you see which line of the C code you're missing in the assembly version?
Also, if you're using MIPS with branch delay slots, even beq
and bne
need nop
s, not just j
and jr
.
Upvotes: 0