diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-08 20:41:09 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-08 20:41:09 -0400 |
commit | eee77999764131bd35ce2c471d32cd0b6e85f598 (patch) | |
tree | 9478c68c0941bdf0ec5fac8d1a0c8122b94b0fd3 | |
parent | 3f98f3dbf56811b481e5c422fe3c68e933802a76 (diff) |
Add write function assembly
-rw-r--r-- | gen_code.c | 10 | ||||
-rw-r--r-- | pc.l | 5 |
2 files changed, 15 insertions, 0 deletions
@@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> +#include <string.h> #include "gen_code.h" #include "pc.h" @@ -128,6 +129,15 @@ ptree *t; } break; case PCALL: + if (!strcmp(t->l->attr.nval->name, "write")) { + GEN_EXPR(t->r); + fprintf(stdout, "mov %s, %%rsi\n", *reg_ptr); + fprintf(stdout, "leaq int_print(%%rip), %%rdi\n"); + fprintf(stdout, "mov $0, %%rax\n"); + fprintf(stdout, "call printf\n"); + } else if (!strcmp(t->l->attr.nval->name, "read")) { + fprintf(stderr,"Read\n"); + } fprintf(stderr, "PCALL\n"); break; case FCALL: @@ -43,6 +43,11 @@ output { tmp->func_info->argc = -1; tmp->func_info->argv = NULL; + fprintf(stdout, ".data\n"); + fprintf(stdout, "int_print:\n\t .asciz \"%%d\\n\"\n"); + fprintf(stdout, "float_print:\n\t .asciz \"%%f\\n\"\n.text\n"); + + return IO; } |