aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-03 05:02:49 -0500
committerMustafa Quraish <[email protected]>2022-02-03 05:02:49 -0500
commit3472a08969b4d7c7ec8f63e608978216749b062d (patch)
tree77a85066c2d5bb47d94befb3e972412048079b80 /src
parentAdd helper to create builtins for syscalls + implement `read()` (diff)
downloadcup-3472a08969b4d7c7ec8f63e608978216749b062d.tar.xz
cup-3472a08969b4d7c7ec8f63e608978216749b062d.zip
Push `argc` and `argv` to the `main()` function
Diffstat (limited to 'src')
-rw-r--r--src/generator.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/generator.c b/src/generator.c
index 829bf73..6fcccbf 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -454,6 +454,13 @@ void generate_asm(Node *root, FILE *out)
fprintf(out, "global _start\n");
fprintf(out, "_start:\n");
#endif
+ // Push argv
+ fprintf(out, " mov rax, rsi\n");
+ fprintf(out, " push rax\n");
+ // Push argc
+ fprintf(out, " mov rax, rdi\n");
+ fprintf(out, " push rax\n");
+
fprintf(out, " call func_main\n");
fprintf(out, " mov rdi, rax\n");
@@ -468,6 +475,9 @@ void generate_asm(Node *root, FILE *out)
// Global strings
fprintf(out, "section .data\n");
+ // TODO: Don't to this here because a string containing a backtick will
+ // cause invalid output and break everything. Maybe just output the
+ // byte values.
for (i64 i = 0; i < num_string_literals; i++) {
fprintf(out, " global_string_%lld: db `%s`, 0\n", i, all_string_literals[i]);
}