commit c7c59e8b4b160b64b813cf6a3ef05a46ff517c2e
parent c71d8831b23364926de62eb53dfca4b1c18edee9
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Tue, 14 Dec 2021 17:08:45 -0600
fix stack addressing
RBP indicates the "front" of the stack, and the stack grows downward
in memory. So local variables will be allocated below the content of
RBP.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
@@ -97,7 +97,7 @@ decl_fromreg(char *buf, struct decl *decl, enum reg reg)
total += mov_m64_r64(buf ? buf + total : NULL, decl->loc.addr, reg);
break;
case DECL_STACK:
- total += mov_disp8_m64_r64(buf, reg, decl->loc.off, RBP);
+ total += mov_disp8_m64_r64(buf, reg, -decl->loc.off, RBP);
break;
default:
fprintf(stderr, "%d\n", decl->kind);
@@ -117,7 +117,7 @@ decl_toreg(char *buf, enum reg reg, struct decl *decl)
total += mov_r64_m64(buf ? buf + total : NULL, reg, decl->loc.addr);
break;
case DECL_STACK:
- total += mov_disp8_r64_m64(buf, reg, RBP, decl->loc.off);
+ total += mov_disp8_r64_m64(buf, reg, RBP, -decl->loc.off);
break;
default:
die("unknown decl type!");