(3.8) [10] The following program tries to copy words from the
address in register $4 to the address in register $5, counting the
number of words copied in register $2. The program stops copying
when it finds a word equal to 0. You do not have to preserve the contents
of register $3, $4, and $5. This terminating word should be copied
but not be counted.
loop: lw $3, 0($4) # Read next word from source
addi $2, $2, 1 # Increment count words copied
sw $3, 0($5) # Write to destination
addi $4, $4, 1 # Advance pointer to next source
addi $5, $5, 1 # Advance pointer to next dest
bne $3, $0, loop # Loop if word copied is not zero
There are multiple bugs in this MIPS program. Fix them and turn
in a bugfree version of this program. Like many of the exercises in
this chapter, the easiest way to write MIPS programs is to use the
simulator described in Appendix A (The program can be evoked by
xspim).