aboutsummaryrefslogtreecommitdiff
path: root/asm/lexer.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:56:40 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:56:40 +0000
commit740627b12dc33aec2753363a3f5bebf10db07cb5 (patch)
treef2e4d394373e47daebe74496112e21ba2fe99b17 /asm/lexer.c
parentac3270777b3f9a13bb94c99e9fad041775d3f070 (diff)
downloadovm-740627b12dc33aec2753363a3f5bebf10db07cb5.tar.gz
ovm-740627b12dc33aec2753363a3f5bebf10db07cb5.tar.bz2
ovm-740627b12dc33aec2753363a3f5bebf10db07cb5.zip
Implemented MALLOC_STACK and SUB in the assembler
Diffstat (limited to 'asm/lexer.c')
-rw-r--r--asm/lexer.c16
1 files changed, 15 insertions, 1 deletions
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;