From a68295151788760d694ef136b00c773973aba772 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 12 May 2023 22:06:18 +0100 Subject: Add .ds directive --- tr8as.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tr8as.c') diff --git a/tr8as.c b/tr8as.c index cfaa80b..0237683 100644 --- a/tr8as.c +++ b/tr8as.c @@ -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 }, -- cgit v1.2.3