Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. The following program tries to copy words from the address in register $a0 to

ID: 3545054 • Letter: 2

Question

2. The following program tries to copy words from the address in register $a0 to the address in register $a1, counting the number of words copied in register $v0. The program stops copying when it finds a word equal to 0. This terminating word should be copied but not counted. You do not have to preserve the contents of registers $v1, $a0, and $a1.

loop:      lw $v1, 0($a0)                      # Read next word from source

addi $v0, $v0, 1                  # Increment count words copied

sw $v1, 0($a1)                     # Write to destination

addi $a0, $a0, 1                 # Increment pointer to next source

addi $a1, $a1, 1                 # Increment pointer to next destination

bne $v1, $zero, loop       # Loop if word copied is different from 0

There are multiple bugs in this MIPS program. Fix them and turn in a bug-free version. You may want to use a MIPS simulator to check your program.

Explanation / Answer

please rate - thanks

any questions ask



.text
.globl main
main:
la $a0,words
li $v0,0
la $a1,copy




loop:
lw $v1, 0($a0) # Read next word from source    
beq $v1, $zero,done # Loop if word copied is different from 0     --do first don't want to process 0
addi $v0, $v0, 1 # Increment count words copied
sw $v1, 0($a1) # Write to destination
addi $a0, $a0, 4 # Increment pointer to next source   --a word is 4 not 1, so must add 4
addi $a1, $a1, 4 # Increment pointer to next destination    -a word is 4 not 1, so must add 4
j loop





done:
.data
words: .word 1,2,3,4,5,6,0
copy: .space 100




after program runs


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote