diff options
author | Adam NAILI | 2018-04-23 13:00:31 +0200 |
---|---|---|
committer | Adam NAILI | 2018-04-23 13:00:31 +0200 |
commit | 2793b31c330396956e4fbeef454e26a37b055ebd (patch) | |
tree | 154246f29ab440669157a558afbad63e75e4f62a | |
parent | a33ad7d7a547dc59cbee6146e1bd0cf16f4fdb62 (diff) | |
download | tpc-compiler-2793b31c330396956e4fbeef454e26a37b055ebd.tar.gz |
Print function done, the most basic asm code on stdout generated
-rw-r--r-- | src/tpc.y | 45 |
1 files changed, 17 insertions, 28 deletions
@@ -42,40 +42,29 @@ static int status = GLOBAL; | |||
42 | %precedence ELSE | 42 | %precedence ELSE |
43 | 43 | ||
44 | %% | 44 | %% |
45 | Prog:{printf("section .data\n"); | 45 | Prog:{printf("extern printf\n"); |
46 | printf("format_entier db \"%%d \n\", 10,0"); | 46 | printf("section .data\n"); |
47 | printf("section .bss\nsection .text\nglobal _start\n"); | 47 | printf("format_int db \"%%d \\n\",10,0\n\n"); |
48 | printf("print:\n"); | 48 | printf("section .bss\nsection .text\n\nglobal _start\n"); |
49 | printf("print: ;print needs an argument in rax\n\n"); | ||
49 | printf("push rbp\n"); | 50 | printf("push rbp\n"); |
50 | printf("mov rbp, rsp\n"); | 51 | printf("mov rbp, rsp\n"); |
51 | |||
52 | printf("push rax\n"); | ||
53 | printf("push rcx\n"); | ||
54 | printf("push rdx\n"); | ||
55 | printf("push rdi\n"); | ||
56 | printf("push rsi\n"); | 52 | printf("push rsi\n"); |
57 | printf("push r8\n"); | 53 | printf("mov rsi, rax\n"); |
58 | 54 | printf("mov rdi, format_int\n"); | |
59 | printf("mov r8, rdx \n"); | 55 | printf("mov rax, 0\n"); |
60 | printf("mov rcx, rcx\n"); | 56 | printf("call printf WRT ..plt\n"); |
61 | printf("mov rdx, rbx\n"); | ||
62 | printf(" mov rdi, format_entier\n"); | ||
63 | printf(" mov rax, 0\n"); | ||
64 | printf(" call printf WRT ..plt\n"); | ||
65 | |||
66 | printf("pop r8\n"); | ||
67 | printf("pop rsi\n"); | 57 | printf("pop rsi\n"); |
68 | printf("pop rdi\n"); | ||
69 | printf("pop rdx\n"); | ||
70 | printf("pop rcx\n"); | ||
71 | printf("pop rax\n"); | ||
72 | |||
73 | printf("pop rbp\n"); | 58 | printf("pop rbp\n"); |
74 | printf("ret\n"); | 59 | printf("ret\n"); |
60 | printf("\n_start:\n"); | ||
75 | } | 61 | } |
76 | DeclConsts DeclVars DeclFoncts { | 62 | DeclConsts DeclVars DeclFoncts |
77 | 63 | { | |
78 | glo_display_table();} | 64 | printf("mov rax,60 \n"); |
65 | printf("mov rdi,0 \n"); | ||
66 | printf("syscall \n"); | ||
67 | } | ||
79 | ; | 68 | ; |
80 | DeclConsts: | 69 | DeclConsts: |
81 | DeclConsts CONST ListConst ';' | 70 | DeclConsts CONST ListConst ';' |