Question
Why is this MIPS program giving me a stack overflow error on MIPS and what do I need to change to make it work .text
Why is this MIPS program giving me a stack overflow error on MIPS and what do I need to change to make it work
.text main: #assume value m is already in $t0, n in $t1 add $a0,$0,$t0 add $a1,$0,$t1 jal weightedsum # call procedure add $t3,$0,$v0 # move the return value from $v0 to where we want syscall
weightedsum: addi $sp,$sp,-4 # Moving Stack pointer sw $t0, 0($sp) # Store previous value jal sum add $t0,$v0,$a1 # Procedure Body add $v0,$0,$t0 # Result lw $t0, 0($sp) # Load previous value addi $sp,$sp,4 # Moving Stack pointer jr $ra # return (Copy $ra to PC) sum:
addi $sp,$sp,-4 # Moving Stack pointer sw $t0, 0($sp) # Store previous value add $t0,$v0,$v0 # Procedure Body add $v0,$0,$t0 # Result lw $t0, 0($sp) # Load previous value addi $sp,$sp,4 # Moving Stack pointer jr $ra
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started