Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

to find out greatest common divisor a. prompt user for two integer if both are z

ID: 3615440 • Letter: T

Question

to find out greatest common divisor a. prompt user for two integer if both are zero programeshould terminate b. programeshould implement the gcd algorithm as aprocedure c. you should accept two integer in eax and ebx i get stuck whle writing the procedure for that how to compareand find out the dividor and remainder. i will appreciate if you can provide complete procedure tocall in main programe. it should return the value of the gcd in eax. to find out greatest common divisor a. prompt user for two integer if both are zero programeshould terminate b. programeshould implement the gcd algorithm as aprocedure c. you should accept two integer in eax and ebx i get stuck whle writing the procedure for that how to compareand find out the dividor and remainder. i will appreciate if you can provide complete procedure tocall in main programe. it should return the value of the gcd in eax.

Explanation / Answer

.data
  prompt: .asciiz   "Please enter two integers: "
  result: .asciiz "The GCD ofthe two numbers is: "
  newline: .asciiz " "
terminate: .asciiz "The program isterminating "

.text

main:
li $v0, 4    # issue prompt
la $a0, prompt
syscall

li $v0, 5    # get n from user
move $s0, $v0
syscall

jal sub_program   #execute sub program with one variable
move $s5, $s0

li $v0, 4    # print "The GCD of the numbers is:"
la $a0, result
syscall

li $v0, 1    # print sum
move $a0, $s5
syscall

#Terminate Program

li $v0, 4    # print newline
la $a0, newline
syscall

li $v0, 10    # terminate the program
syscall

sub_program:

addi $s5, $s0, 10
jr $ra #jumpto where call was implemented