From 740627b12dc33aec2753363a3f5bebf10db07cb5 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Nov 2023 22:56:40 +0000 Subject: Implemented MALLOC_STACK and SUB in the assembler --- asm/lexer.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'asm/lexer.c') diff --git a/asm/lexer.c b/asm/lexer.c index dfc4976..0a8a97e 100644 --- a/asm/lexer.c +++ b/asm/lexer.c @@ -44,6 +44,8 @@ const char *token_type_as_cstr(token_type_t type) return "DUP"; case TOKEN_MALLOC: return "MALLOC"; + case TOKEN_MALLOC_STACK: + return "MALLOC_STACK"; case TOKEN_MSET: return "MSET"; case TOKEN_MSET_STACK: @@ -76,6 +78,8 @@ const char *token_type_as_cstr(token_type_t type) return "GTE"; case TOKEN_PLUS: return "PLUS"; + case TOKEN_SUB: + return "SUB"; case TOKEN_MULT: return "MULT"; case TOKEN_PRINT: @@ -131,7 +135,7 @@ bool is_valid_hex_char(char c) token_t tokenise_symbol(buffer_t *buffer, size_t *column) { - static_assert(NUMBER_OF_OPCODES == 90, "tokenise_buffer: Out of date!"); + static_assert(NUMBER_OF_OPCODES == 96, "tokenise_buffer: Out of date!"); size_t sym_size = 0; for (; sym_size < space_left(buffer) && @@ -182,6 +186,11 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column) offset = 3; type = TOKEN_DUP; } + else if (sym_size >= 12 && strncmp(opcode, "MALLOC.STACK", 12) == 0) + { + offset = 12; + type = TOKEN_MALLOC_STACK; + } else if (sym_size >= 6 && strncmp(opcode, "MALLOC", 6) == 0) { offset = 6; @@ -262,6 +271,11 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column) offset = 2; type = TOKEN_GT; } + else if (sym_size >= 3 && strncmp(opcode, "SUB", 3) == 0) + { + offset = 3; + type = TOKEN_SUB; + } else if (sym_size >= 4 && strncmp(opcode, "PLUS", 4) == 0) { offset = 4; -- cgit v1.2.3-13-gbd6f