Question: .data largestPrimeFactor: .word 0 .text main: li $t0, 2 li $t1, 1 li $t2, 100 loop: div $t3, $t2, $t0 mfhi $t3 bne $t3, $0,

.data

largestPrimeFactor: .word 0

.text

main:

li $t0, 2

li $t1, 1

li $t2, 100

loop:

div $t3, $t2, $t0

mfhi $t3

bne $t3, $0, notFactor

li $t1, 0

li $t4, 2

innerLoop:

div $t5, $t0, $t4

mfhi $t5

bne $t5, $0, notPrime

li $t1, 1

notPrime:

addi $t4, $t4, 1

blt $t4, $t0, innerLoop

bne $t1, $0, update

notFactor:

addi $t0, $t0, 1

blt $t0, $t2, loop

update:

sw $t0, largestPrimeFactor($0)

li $v0, 1

lw $a0, largestPrimeFactor($0)

syscall

li $v0, 10

syscall

This Assembly MIPS instructions give me the wrong answer 2 instead of the right answer 5.

Can you correct this code and give me the corrected code?

Please make sure the code is working correctly by using Online MIPS Simulator, I asked more than once and all the code answers has been wrong

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!