Implemented MALLOC_STACK and SUB in the assembler

This commit is contained in:
2023-11-01 22:56:40 +00:00
parent ac3270777b
commit 740627b12d
3 changed files with 23 additions and 1 deletions

View File

@@ -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;

View File

@@ -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,

View File

@@ -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);