# Calculate the Greatest Common Divisor (GCD) or two integers # according to the Euclid's algorithm: # If B=0 then Return A else Return Euclid(B, A mod B) .text .globl __start __start: li $v0, 4 la $a0, First syscall # Ask for the first integer li $v0, 5 syscall # Read an integer add $t0, $0, $v0 # and store it in $t0 li $v0, 4 la $a0, Second syscall # Ask for the second integer li $v0, 5 syscall # Read an integer add $t1, $0, $v0 # and store it in $t1 loop: div $t0, $t1 mfhi $t2 # $t2 = $t0 mod $t1 add $t0, $0, $t1 # $t0 = $t1 add $t1, $0, $t2 # $t1 = $t2 bne $t1, $0, loop li $v0, 4 la $a0, Ans syscall # Print "The GCD is: " add $a0, $0, $t0 li $v0, 1 syscall # Print GCD li $v0, 4 la $a0, nl syscall # Print new line b __start # Go to __start (running into loop) .data First: .asciiz "Calculating GCD of two integers.\nEnter first integer: " Second: .asciiz "Enter second integer: " Ans: .asciiz "Their GCD is: " nl: .asciiz "\n\n"