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

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!