Professor Mune had wirtten a compiler by ocmal ssee it on https://www.ed.tus.ac.jp/j-mune/ccp/
I had some test cases.
A test program for output integer, The source code like the following:
{
int a, b;
scan (a);
}
The generated assembly code like the following:
IO:
.string "%lld"
.text
.globl main
main:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movq %rbp, %rax
leaq -8(%rax), %rax
movq %rax, %rsi
leaq IO(%rip), %rdi
movq $0, %rax
callq scanf
leaveq
retq
Then gcc input.s
a a.exe file is generated, run it in Windows console window, crashed, why?
i installed Embarcadero_Dev-Cpp_6.3_TDM-GCC_9.2_Setup on my Windows, therefore I have gcc 64-bit.
I fix the issue in code emitter, the new code like the following
$ cat -n tmp.s
1 IO:
2 .string "%lld"
3 .text
4 .globl main
5 main:
6 pushq %rbp
7 movq %rsp, %rbp
8 subq $32, %rsp
9 movq %rbp, %rax
10 leaq -8(%rax), %rax
11 movq %rax, %rdx
12 leaq IO(%rip), %rcx
13 subq $32, %rsp
14 callq scanf
15 addq $32, %rsp
16 leaveq
17 retq