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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started