Question: THe code I did is wrong and wont give me the correct answer. IM USING MIPS 4 . 5 THis is the 4 th time

THe code I did is wrong and wont give me the correct answer. IM USING MIPS 4.5 THis is the 4th time asking again Write a MIPS program that asks the user for an integer n, uses a recursive function to find the sum of all numbers from 1 to n, and prints the result. Enter an integer n: 7 The sum of numbers from 1 to n is: 4
-- program is finished running --
Enter an integer n:1
Enter an integer n :
Enter an integer n: Enter an integer: 7
The sum of numbers from 1 to 4 is: 14
Clear
-- program is finished running -
Enter an integer: 7
Enter an integer n: 7 The sum of numbers from 1 to n is: 4
The sum of numbers from 1 to n is: -- program is finished running --
For example, if the user entered 6, the program should add 1+2+3+4+5+6 and output 21.
Make sure to have prompts for user input and output.
SUBMIT:
1).asm file
2) Output of the program with user input of 7. So
Heres my code that I got from someone. PLEASE MAKE SURE YOU CONFIRM IT USING THE MIPS PROGRAM MARS 4.5. and show the screenshot plese output please. I have a picture of what I keep getting and the picture of the question.
.data
prompt: .asciiz "Enter an integer n: "
result: .asciiz "The sum of numbers from 1 to n is: "
.text
.globl main
main:
# Print prompt
li $v0,4
la $a0, prompt
syscall
# Read integer from user
li $v0,5
syscall
move $a0, $v0 # Move the read integer to $a0 for recursion function
# Call the recursive function
jal sum_recursion
# Print result prompt
li $v0,4
la $a0, result
syscall
# Print the result
move $a0, $v0 # Result of recursion is in $v0, move it to $a0
li $v0,1
syscall
# Exit program
li $v0,10
syscall
# Recursive function to calculate sum from 1 to n
sum_recursion:
# Base case: if n =0, return 0
blez $a0, base_case
# Recursive case: return n + sum_recursion(n -1)
addi $sp, $sp,-8 # Allocate space on stack for return address and argument
sw $ra,0($sp) # Store return address
sw $a0,4($sp) # Store current argument n
addi $a0, $a0,-1 # Decrement n
jal sum_recursion # Recursive call
lw $a0,4($sp) # Load the original n
lw $ra,0($sp) # Restore return address
addi $sp, $sp,8 # Deallocate stack space
add $v0, $v0, $a0 # Add n to the result of recursion
jr $ra # Return to caller
base_case:
li $v0,0 # Load 0 into $v0 for base case result
jr $ra # Return to caller
 THe code I did is wrong and wont give me the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!