diff --git a/task1/CodegenImpl.java b/task1/CodegenImpl.java index c0b1c37..c2c87d4 100644 --- a/task1/CodegenImpl.java +++ b/task1/CodegenImpl.java @@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen { // set frame pointer to start of arguments "addi s0,sp,8\n" + "call " + methodLabel + "\n" + // restore stack to frame pointer - 8 (bottom of frame) + // this ensures any stack growth inside the method is undone + + "addi sp,s0,-8\n" // restore old frame pointer & stack pointer + "lw s0,4(sp)\n" + "lw sp,(sp)\n" diff --git a/task2/CodegenImpl.java b/task2/CodegenImpl.java index c0b1c37..c2c87d4 100644 --- a/task2/CodegenImpl.java +++ b/task2/CodegenImpl.java @@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen { // set frame pointer to start of arguments "addi s0,sp,8\n" + "call " + methodLabel + "\n" + // restore stack to frame pointer - 8 (bottom of frame) + // this ensures any stack growth inside the method is undone + + "addi sp,s0,-8\n" // restore old frame pointer & stack pointer + "lw s0,4(sp)\n" + "lw sp,(sp)\n" diff --git a/task3/CodegenImpl.java b/task3/CodegenImpl.java index c0b1c37..c2c87d4 100644 --- a/task3/CodegenImpl.java +++ b/task3/CodegenImpl.java @@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen { // set frame pointer to start of arguments "addi s0,sp,8\n" + "call " + methodLabel + "\n" + // restore stack to frame pointer - 8 (bottom of frame) + // this ensures any stack growth inside the method is undone + + "addi sp,s0,-8\n" // restore old frame pointer & stack pointer + "lw s0,4(sp)\n" + "lw sp,(sp)\n"