Homework Solution: The following program tries to copy words from the address in register $a0 to the address in register $a1, counting the numbe…

    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 Sv0. The program stops copying when it finds a word equal to 0. You do not have to preserve the contents of registers Sv1, Sa0, and $a1. This terminating word should be copied but not counted 1. addi $vO. $zero, 0 lw Sv1, 0(Sao) sw Sv1, 0(Sa1) addi Sa0, Sa0, 4 addi $a1, Sa1,4 # Initialize count # Read next word from source # Write to destination # Advance pointer to next source # Advance pointer to next destination loop: beq $v1, $zero, loop # Loop if word copied != zero There are multiple bugs in this MIPS program; fix them and turn in a bug-free version.
    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. You do not have to preserve the contents of registers $v1, $a0, and $a1. This terminating word should be copied but not counted. addi $v0. $zero, 0 # Initialize count loop: lw $v1, 0 ($a0) # Read next word from source sw $v1, 0 ($a1) # Write to destination addi $a0, $a0, 4 # Advance pointer to next source # addi $a1, $a1, 4 #Advance pointer to next destination beq $v1, $zero, loop # Loop if word copied ! = zero There are multiple bugs in this MIPS program: fix them and turn in a bug-free version.

    Expert Answer

     
    Ans:: The multiple bugs to be fixed are the following::

    The aftercited program tries to vision suffrage from the discourse in record $a0 to the discourse in record $a1, reckoning the reckon of suffrage copied in record Sv0. The program stops visioning when it finds a engagement resembling to 0. You do referable attributable attributable attributable feel to maintain the space of records Sv1, Sa0, and $a1. This terminating engagement should be copied excepting referable attributable attributable attributable reckoned 1. addi $vO. $zero, 0 lw Sv1, 0(Sao) sw Sv1, 0(Sa1) addi Sa0, Sa0, 4 addi $a1, Sa1,4 # Initialize reckon # Read instant engagement from beginning # Write to location # Advance pointer to instant beginning # Advance pointer to instant location loop: beq $v1, $zero, loop # Loop if engagement copied != naught There are multiple bugs in this MIPS program; establish them and revolve in a bug-frank statement.

    The aftercited program tries to vision suffrage from the discourse in record $a0 to the discourse in record $a1, reckoning the reckon of suffrage copied in record $v0. The program stops visioning when it finds a engagement resembling to 0. You do referable attributable attributable attributable feel to maintain the space of records $v1, $a0, and $a1. This terminating engagement should be copied excepting referable attributable attributable attributable reckoned. addi $v0. $zero, 0 # Initialize reckon loop: lw $v1, 0 ($a0) # Read instant engagement from beginning sw $v1, 0 ($a1) # Write to location addi $a0, $a0, 4 # Advance pointer to instant beginning # addi $a1, $a1, 4 #Advance pointer to instant location beq $v1, $zero, loop # Loop if engagement copied ! = naught There are multiple bugs in this MIPS program: establish them and revolve in a bug-frank statement.

    Expert Defense

     

    Ans::

    The multiple bugs to be established are the aftercited::

    1.Bug-1 : Reckon ‘$v0’ is initialized to 0., referable attributable attributable attributable to –1 to abandoning reckoning the 0 engagement.

    2.Bug-2 : reckon ‘$v0’ isn’t incremented.

    3.Bug-3 : Loops if the worrd copied is resemblings to 0 rathr than referable attributable attributable-equals.

    => The Bug frank statement is as below:-

    For absolved interpret I place verse reckons.

    First single is $vo init to -1 in verse 1.

    1. addi $v0, $zero, -1 # Initializing to abandon reckonng 0 engagement.

    2. loop:: lw, $v1, 0($a0) # Reading the instant engagement frm the beginning.

    3. addi $v0, $v0, 1 # Incrementing the reckon-engagement copied.

    4. sw $v1, 0($a1) # Writing it to the destintion.

    5. addi $a0, $a0, 4 # Advnce-pointer to the instant-source.

    6. addi $a1, $a1, 4 # Advnce-pointer to the instant-destination.

    7. bne $v1, $zero, loop # Looping if the engagement copied referable attributable attributable attributable resemblings ( != ) to 0.

    // Thank you //