Fix variable offsets being calculated wrong relative to s0

This commit is contained in:
Henry 2019-12-20 15:55:00 +00:00
parent bb75a6a03e
commit ba755de84c
3 changed files with 6 additions and 6 deletions

View File

@ -56,7 +56,7 @@ public class CodegenImpl implements Codegen {
+ "mv t1,a0\n"
+ compileExpBinop(b.binop);
} else if (e instanceof Variable) {
int offset = ((Variable) e).x;
int offset = ((Variable) e).x - 1;
return String.format("lw a0,%d(s0)\n", offset * 4);
} else if (e instanceof Invoke) {
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
Assign assign = (Assign) e;
return compileExp(assign.e)
+ String.format("sw a0,%d(s0)\n", assign.x * 4);
+ String.format("sw a0,%d(s0)\n", (assign.x - 1) * 4);
} else if (e instanceof Continue) {
return "jr s2\n";
} else if (e instanceof Break) {

View File

@ -56,7 +56,7 @@ public class CodegenImpl implements Codegen {
+ "mv t1,a0\n"
+ compileExpBinop(b.binop);
} else if (e instanceof Variable) {
int offset = ((Variable) e).x;
int offset = ((Variable) e).x - 1;
return String.format("lw a0,%d(s0)\n", offset * 4);
} else if (e instanceof Invoke) {
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
Assign assign = (Assign) e;
return compileExp(assign.e)
+ String.format("sw a0,%d(s0)\n", assign.x * 4);
+ String.format("sw a0,%d(s0)\n", (assign.x - 1) * 4);
} else if (e instanceof Continue) {
return "jr s2\n";
} else if (e instanceof Break) {

View File

@ -56,7 +56,7 @@ public class CodegenImpl implements Codegen {
+ "mv t1,a0\n"
+ compileExpBinop(b.binop);
} else if (e instanceof Variable) {
int offset = ((Variable) e).x;
int offset = ((Variable) e).x - 1;
return String.format("lw a0,%d(s0)\n", offset * 4);
} else if (e instanceof Invoke) {
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
Assign assign = (Assign) e;
return compileExp(assign.e)
+ String.format("sw a0,%d(s0)\n", assign.x * 4);
+ String.format("sw a0,%d(s0)\n", (assign.x - 1) * 4);
} else if (e instanceof Continue) {
return "jr s2\n";
} else if (e instanceof Break) {