From 09af190aa9a7b41057547114c7fa53ce4d4cdc77 Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 23 Apr 2023 19:20:09 +0100 Subject: [PATCH] Fix rsp not being escaped properly in the Win32 GAS ASM generator --- src/assemble/ASMAssembler.c | 4 ++-- tests/print.em | 1 + tests/printf.er | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tests/print.em diff --git a/src/assemble/ASMAssembler.c b/src/assemble/ASMAssembler.c index b60f724..2384aad 100644 --- a/src/assemble/ASMAssembler.c +++ b/src/assemble/ASMAssembler.c @@ -702,13 +702,13 @@ static int AsCall(struct SymbolTableEntry* Entry, int Args) { printf("\t\t\tFunction returns into %s\n", Registers[OutRegister]); // Allocate shadow space - fprintf(OutputFile, "\taddq\t$-32, %rsp\n"); + fprintf(OutputFile, "\taddq\t$-32, %%rsp\n"); fprintf(OutputFile, "\tcall\t%s\n", Entry->Name); // Deallocate arguments and stack space. if (Args > 4) fprintf(OutputFile, "\taddq\t$%d, %%rsp\n", (8 * (Args - 4)) + 32); else - fprintf(OutputFile, "\taddq\t$32, %rsp\n"); + fprintf(OutputFile, "\taddq\t$32, %%rsp\n"); fprintf(OutputFile, "\tmovq\t%%rax, %s\n", Registers[OutRegister]); diff --git a/tests/print.em b/tests/print.em new file mode 100644 index 0000000..a96efb1 --- /dev/null +++ b/tests/print.em @@ -0,0 +1 @@ +int :: printf(char* fmt); \ No newline at end of file diff --git a/tests/printf.er b/tests/printf.er index 9b173a2..4596c9f 100644 --- a/tests/printf.er +++ b/tests/printf.er @@ -1,4 +1,4 @@ -import "print.em" +import "tests/print.em" int :: main () { printf("%s\r\n", "hi there");