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

2 (7 points) The following program tries to copy words from the address in regis

ID: 2248008 • Letter: 2

Question

2 (7 points) The following program tries to copy words from the address in register $84 to the address in register Ss5, counting the number of words copied in register Ss2. The program stops copying when it finds a word equal to O.You do not have to preserve the contents of registers St3, Ss4, and Ss5. This terminating word should be copied but not counted. Loop: St3, 0($54) # Read next word from source # Increment count of words copied # Write to destination # Advance pointer to next source # Advance pointer to next destination #goto Loop ifword copied != zero hv addi Ss2, Ss2, 1 addi addi bne $84, Ss4, 1 5, Ss5, 1 $t3, Szero, Loop There multiple bugs in this MIPS program. Fix them and turn in a bug-free version of this program

Explanation / Answer

Answer:- The errors found as-

1. Spacing in between s and 5 in second last addi instruction.

2. Counting is being done before checking of read value zero in the second line of the code.

So the modified code can be written as (assuming all addresses in $s4 and $s5 are already present and counter value is initially zero)-

Loop1: lw $t3, 0($s4) #read value gtom source

beq $t3, $zero, ZeroFnd #if value read is zero then goto label name specified as ZeroFnd

addi $s2, $s2, 1 #otherwise add one to counter

sw $t3, 0($s5) #copy to destination

addi $s4, $s4, 1 #increase source address by one

addi $s5, $s5, 1 #increase destination address by one

j Loop1 #goto label named as Loop1

ZeroFnd: sw $t3, 0($s5) #load value zero to destination

#end of code

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