2 years ago

#57

test-img

Anirudd Pokhrel

How can I find only the Greatest Prime Factor of three integers in MIPS?

I have my MIPS algorithm to print the Greatest Common Factor of three integers. For example in this code, if you enter 12, 18 and 24, you get the output 6 which is the Greatest Common Factor. But I want the code to print 3 as it is the Greatest Common Prime Factor in all of these integers. How can I do this by amending the code I have? Can anyone help me please? I am new to MIPS and I have been working on this code for the past week. Here is my code:

main:
.data

    prompt: .asciiz "Enter 3 positive numbers: "
    message1: .asciiz "\n First integer: "
    message2: .asciiz "\n Second integer: "
    message3: .asciiz "\n Third integer: "
    message4: .asciiz "\n The Greatest Common Prime Factor is:"

cd:
.text
    li $v0, 4
    la $a0, prompt
    syscall

    li $v0, 4
    la $a0, message1
    syscall

    li $v0, 5
    syscall
    move $t0, $v0

    li $v0, 4
    la $a0, message2
    syscall

    li $v0, 5
    syscall
    move $t1, $v0

    li $v0, 4
    la $a0, message3
    syscall

    li $v0, 5
    syscall
    move $t2, $v0

    #move $t0, $k0
    #move $t1, $k1
    #move $t2, $k2

loop:
    beq $t1, $0, done
    div $t0, $t1
    move $t0, $t1
    mfhi $t1
    j loop

done:   
    li $v0, 4
    la $a0, message4
    syscall

    li $v0, 1
    move $a0, $t0   
    #move $v0, $t0
    #jr $ra
    syscall
    
    li $v0, 10
    syscall

assembly

mips

qtspim

0 Answers

Your Answer

Accepted video resources