diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-12 22:06:18 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-12 22:06:18 +0100 |
commit | a68295151788760d694ef136b00c773973aba772 (patch) | |
tree | 0c4272f1a69bb609a673eba29693aa8223a3b89e /tr8as.c | |
parent | 9e4698a5212e3fccea30145ec41ee7ac822bcd0b (diff) | |
download | tr8vm-a68295151788760d694ef136b00c773973aba772.tar.gz tr8vm-a68295151788760d694ef136b00c773973aba772.zip |
Add .ds directive
Diffstat (limited to 'tr8as.c')
-rw-r--r-- | tr8as.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -770,6 +770,54 @@ static uint8_t parse_dw(As *as, char **c) return 1; } +static uint8_t parse_ds(As *as, char **c) +{ + char word[MAX_ID + 1]; + uint8_t wlen; + uint16_t count = 0xff, imm = 0xff; + + /* .ds count, imm */ + + if (!next_word(as, c, word, &wlen)) + return 0; + + if (wlen == 0) + return error_l("Syntax error", &as->loc, "expected count"); + + if (!next_imm(as, word, &count)) + return error_l("Syntax error", &as->loc, "expected count"); + + *c = skip_whitespace(*c); + if (**c != ',') + return error_l("Syntax error", &as->loc, "expected ,"); + (*c)++; + + if (!next_word(as, c, word, &wlen)) + return 0; + + if (wlen == 0) + return error_l("Syntax error", &as->loc, "expected immediate"); + + if (next_imm(as, word, &count)) + { + if (imm > 0xff) + return error_l("Overflow in immediate", &as->loc, word); + } + else + return error_l("Syntax error", &as->loc, "expected immediate"); + + if (as->addr + count > UINT16_MAX) + return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes"); + + for (uint16_t i = 0; i < count; i++) + as->out[as->addr++] = imm & 0xff; + + if (as->addr > as->size) + as->size = as->addr; + + return 1; +} + static uint8_t parse_nop(As *as, char **c) { /* NOP */ @@ -1530,6 +1578,7 @@ static InstParse insts[] = { ".equ", parse_equ }, { ".db", parse_db }, { ".dw", parse_dw }, + { ".ds", parse_ds }, { "halt", parse_halt }, { "push", parse_push }, { "port", parse_port }, |