This code is written in MIPS language. When I run the code on Mars 4.5, it gives me this error on line 31: Runtime exception at 0x00400040: arithmetic overflow. Please solve the error or rewrite the program, but don't use the function "multi".
.data
result: .word 0 # reserve space in the data segment for the result variable
.text
.globl main
main:
# Initialize $s0 and $s1
lui $s0, 0x1234 # upper 16 bits of $s0 = 0x1234
ori $s0, $s0, 0x5678 # lower 16 bits of $s0 = 0x5678
lui $s1, 0x1111 # upper 16 bits of $s1 = 0x1111
ori $s1, $s1, 0x2222 # lower 16 bits of $s1 = 0x2222
# Call the multiplication function with $s0 and $s1 as arguments
move $a0, $s0 # first argument is $s0
move $a1, $s1 # second argument is $s1
jal mult # call the multiplication function
# Load the result from memory into $v0
lw $v0, result
# Exit the program
li $v0, 10
syscall
mult:
addi $sp, $sp, -4 # reserve space on the stack for the return value
li $t0, 0 # initialize a counter to zero
li $t1, 0 # initialize a temporary variable to zero
loop:
bge $t0, $a1, end_loop # if counter >= second argument, exit the loop
add $t1, $t1, $a0 # add the first argument to the temporary variable
addi $t0, $t0, 1 # increment the counter
j loop # jump back to the beginning of the loop
end_loop:
sw $t1, result # store the result in memory
addi $sp, $sp, 4 # deallocate space on the stack
jr $ra # return to the calling function