Question
I am trying to do this question where I have to find the greatest common prime factor from three integers. I got the prime factors
I am trying to do this question where I have to find the greatest common prime factor from three integers. I got the prime factors from each of them and stored each of the prime factors in individual arrays. Now, I want to get the greatest common value from the three arrays. I don't know how to get the greatest common value from the three arrays. Here is the code I have so far:
.data q: .asciiz "Enter a number to factor: " r: .asciiz "The prime factorization of " r2: .asciiz " is " comma: .asciiz ", " n1: .asciiz ". " space: .asciiz " " arr1: .space 64 #array with 8 elements arr2: .space 64 arr3: .space 64 .text
#used: $t0, $t1, $t2, $t3
main:
#should initialize array values to 1 ########### # First Number ########### li $v0, 4 la $a0, q syscall
li $v0, 5 syscall move $t0, $v0 #the input
li $v0, 4 la $a0, r syscall li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, r2 syscall
li $t1, 2
addi $t3, $zero, 0 #array index = 0
while: bge $t1, $t0, endWhile
div $t0, $t1 mfhi $t2 bnez $t2, else #if n%2 == 0; else
#$t1 has the value we need, should store $t1 in array sw $t1, arr1($t3) addi $t3, $t3, 4 #array index ++
li $v0, 1 move $a0, $t1 syscall
li $v0, 4 la $a0, comma syscall
mflo $t0
j while
else: addi $t1, $t1, 1
j while endWhile: sw $t0, arr1($t3) #saving the last value $t0 in the array
li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, n1 syscall
########### # Second Number ########### li $v0, 4 la $a0, q syscall
li $v0, 5 syscall move $t0, $v0 #the input
li $v0, 4 la $a0, r syscall li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, r2 syscall
li $t1, 2
addi $t3, $zero, 0 #array index=0
while2: bge $t1, $t0, endWhile2
div $t0, $t1 mfhi $t2 bnez $t2, else2 #if n%2 == 0; else
#$t1 has the value we need, should store $t1 in array sw $t1, arr1($t3) addi $t3, $t3, 4 #array index ++
li $v0, 1 move $a0, $t1 syscall
li $v0, 4 la $a0, comma syscall
mflo $t0
j while2
else2: addi $t1, $t1, 1
j while2 endWhile2: sw $t0, arr1($t3) #saving the last value $t0 in the array
li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, n1 syscall
########### # Third Number ########### li $v0, 4 la $a0, q syscall
li $v0, 5 syscall move $t0, $v0 #the input
li $v0, 4 la $a0, r syscall li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, r2 syscall
li $t1, 2
addi $t3, $zero, 0 #array index=0
while3: bge $t1, $t0, endWhile3
div $t0, $t1 mfhi $t2 bnez $t2, else3 #if n%2 == 0; else
#$t1 has the value we need, should store $t1 in array sw $t1, arr1($t3) addi $t3, $t3, 4 #array index ++
li $v0, 1 move $a0, $t1 syscall
li $v0, 4 la $a0, comma syscall
mflo $t0
j while3
else3: addi $t1, $t1, 1
j while3 endWhile3: sw $t0, arr1($t3) #saving the last value $t0 in the array li $v0, 1 move $a0, $t0 syscall
li $v0, 4 la $a0, n1 syscall
#at this point, the prime factors for each number are in their respective arrays
########### # End Program ########### li $v0, 10 syscall
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