Question: I'm writing a MIPS Mars program to find the lowest common multiple of two integers. The function takes 4 values from 4 registers, $a0, $a1,
I'm writing a MIPS Mars program to find the lowest common multiple of two integers. The function takes 4 values from 4 registers, $a0, $a1, $a2, and $a4. I've attached my code below. The program works for fine, except for one if statement. I've commented out the block that's producing an error.

It looks like I'm getting an error when it hits the bgt $a2, $a3, else line. It works fine for when the numbers are equal, and when the first number is bigger than the second number. It breaks when the first number is less than the second number, which is from the bgt line. When I run the program it gives this error message in the console;
Assemble: assembling /Usersame/Desktop/school/class/assignment/LCM_Recursive.asm
Assemble: operation completed successfully. Go: running LCM_Recursive.asm
Error in /Usersame/Desktop/school/class/assignment/LCM_Recursive.asm line 59: Runtime exception at 0x0040010c: address out of range 0x7fbffffc
Go: execution terminated with errors.
This is a screenshot of line 59;

# Function: 1cm recursive # Argument: a0 Ve integer number m $al +ve integer number n $a2temporary LCM by increamenting m, initial is m a3temporary LCM by increamenting n, initial is n # Returns # Purpose: Implementing LCM function using recursive call. lcm_recursive: # Store frame addi $sp, $sp, -28 SW SW Sw SW SW Sw addi $fp, $sp, 28 $fp, 28($sp) $ra, 24($sp) $a0, 20($sp) $a1, 16($sp) $a2, 12($sp) $a3, 8($sp) # Body beq bgt add jal lcm_recursive if lcm-m 1cm-n GOTO 1cm-recursive-end $a2, $a3, lcm_recursive_end $a2, $a3, else $a2, $a2, $a0 (works does not work) (works no issues) # no issues) - else: add jal $a3, $a3, $al lcm_recursive lcm_recursive_end: move $V0, $a2 lcm recursive ret lcm_recursive_ret: # Restore frame $fp, 28($sp) $ra, 24($sp) $a0, 20($sp) $a1, 16($sp) $a2, 12($sp) $a3, 8($sp) Lw LW Lw LW addi $sp, $sp, 28 $ra # jump to caller
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
