From 3472a08969b4d7c7ec8f63e608978216749b062d Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 3 Feb 2022 05:02:49 -0500 Subject: Push `argc` and `argv` to the `main()` function --- src/generator.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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]); } -- cgit v1.2.3