From dad1f6d92793807bc37f866333dd4c412bed257c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20LACROIX?= Date: Tue, 18 Apr 2023 09:44:41 +0200 Subject: [PATCH] Added operations (.c) --- operations.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 operations.c diff --git a/operations.c b/operations.c new file mode 100644 index 0000000..3d9e1a7 --- /dev/null +++ b/operations.c @@ -0,0 +1,73 @@ +// +// Created by chepycou on 4/14/23. +// + +#include +#include "table.h" + +/*prints the ASM instruction for the addition computation + * and returns the address of the temporary variable*/ +int operation_add(int addr1, int addr2){ + int addr = addTempINTAndGetAddress(); + printf("ADD @%d @%d @%d\n", addr, addr1, addr2); + return addr; +} + +/*prints the ASM instruction for the subtraction computation + * and returns the address of the temporary variable*/ +int operation_sub(int addr1, int addr2){ + int addr = addTempINTAndGetAddress(); + printf("SUB @%d @%d @%d\n", addr, addr1, addr2); + return addr; +} + +/*prints the ASM instruction for the multiplication computation + * and returns the address of the temporary variable*/ +int operation_mul(int addr1, int addr2){ + int addr = addTempINTAndGetAddress(); + printf("MUL @%d @%d @%d\n", addr, addr1, addr2); + return addr; +} + +/*prints the ASM instruction for the integer division computation + * and returns the address of the temporary variable*/ +int operation_divInt(int addr1, int addr2){ + int addr = addTempINTAndGetAddress(); + printf("DIV_INT @%d @%d @%d\n", addr, addr1, addr2); + return addr; +} + +/*prints the ASM instruction for the remainder computation + * and returns the address of the temporary variable*/ +int operation_divRem(int addr1, int addr2){ + int addr = addTempINTAndGetAddress(); + printf("DIV_REM @%d @%d @%d\n", addr, addr1, addr2); + return addr; +} + +/*prints the ASM instruction for the affection of a variable + * EX : + * a = 2; + */ +void operation_afc_nb(int addr, int value){ + printf("AFC @%d #%d\n", addr, value); +} + +/*prints the ASM instruction for the affection of a temporary variable + * EX : + * "1_TEMP = 2" + * and returns the address of the temp variable*/ +int operation_afc_nb_tmp(int value){ + int addr = addTempINTAndGetAddress(); + operation_afc_nb(addr, value); + return addr; +} + + +/*prints the ASM instruction for the affection of a temporary variable + * EX : + * a = b; + */ +void operation_afc_addr(int addr1, int addr2){ + printf("AFC @%d @%d\n", addr1, addr2); +} \ No newline at end of file