Here's my code for strncpy. In theory it should work, but when I run tests on it it gives out garbage.
Arguments:
$a0 = pointer to destination array
$a1 = source string
$a2 = number of characters to copy
Returns: the destination array
strncpy:
beqz $a2, out
lb $t0, 0($a1) #load byte
beqz $t0 out
subiu $a2, $a2, 1
sb $t0, 0($a0)
addiu $a0, $a0, 1
addiu $a1, $a1, 1
j strncpy
out:
lb $0 0($a0)
move $v0 $a0
jr $ra