aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
Diffstat (limited to 'asm')
-rw-r--r--asm/lexer.c16
-rw-r--r--asm/lexer.h2
-rw-r--r--asm/parser.c6
3 files changed, 23 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;
diff --git a/asm/lexer.h b/asm/lexer.h
index e8897b6..6b17b04 100644
--- a/asm/lexer.h
+++ b/asm/lexer.h
@@ -27,6 +27,7 @@ typedef enum TokenType
TOKEN_MOV,
TOKEN_DUP,
TOKEN_MALLOC,
+ TOKEN_MALLOC_STACK,
TOKEN_MSET,
TOKEN_MSET_STACK,
TOKEN_MGET,
@@ -43,6 +44,7 @@ typedef enum TokenType
TOKEN_GT,
TOKEN_GTE,
TOKEN_PLUS,
+ TOKEN_SUB,
TOKEN_MULT,
TOKEN_PRINT,
TOKEN_JUMP,
diff --git a/asm/parser.c b/asm/parser.c
index 4b5eee1..08e067c 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -230,6 +230,9 @@ perr_t parse_next_inst(token_stream_t *stream, inst_t *ret)
case TOKEN_MGET:
ret->opcode = OP_MGET_BYTE;
return parse_utype_inst_with_operand(stream, ret);
+ case TOKEN_MALLOC_STACK:
+ ret->opcode = OP_MALLOC_STACK_BYTE;
+ return parse_utype_inst(stream, ret);
case TOKEN_MSET_STACK:
ret->opcode = OP_MSET_STACK_BYTE;
return parse_utype_inst(stream, ret);
@@ -272,6 +275,9 @@ perr_t parse_next_inst(token_stream_t *stream, inst_t *ret)
case TOKEN_PLUS:
ret->opcode = OP_PLUS_BYTE;
return parse_utype_inst(stream, ret);
+ case TOKEN_SUB:
+ ret->opcode = OP_SUB_BYTE;
+ return parse_utype_inst(stream, ret);
case TOKEN_MULT:
ret->opcode = OP_MULT_BYTE;
return parse_utype_inst(stream, ret);