From: Lukas Krickl Date: Thu, 30 Nov 2023 08:23:52 +0000 (+0100) Subject: Moved label code to asmline X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=07cc915f1b98bf5b6a14789eeb82b2cf71af091d;p=ulas%2F.git Moved label code to asmline --- diff --git a/src/ulas.c b/src/ulas.c index bdec825..751220b 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1848,25 +1848,6 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line, return -1; } - // TODO: check for symbol token here... if so add it - // and skip to the next token - if (ulas_tok(&ulas.tok, line, n) == -1) { - ULASERR("Expected label or instruction\n"); - return -1; - } - - // is it a label? - if (ulas_islabelname(ulas.tok.buf, strlen(ulas.tok.buf))) { - start = *line; - // TODO: register label here - - // is next token empty? - if (ulas_tok(&ulas.tok, line, n) == 0 || - strnlen(ulas.tok.buf, ulas.tok.maxlen) == 0) { - return 0; - } - } - const struct ulas_instr *instrs = ULASINSTRS; int written = 0; @@ -2047,9 +2028,22 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { } } else { - // start over for the next step... - line = start; // is regular line in form of [label:] instruction ; comment + // is it a label? + if (ulas_islabelname(ulas.tok.buf, strlen(ulas.tok.buf))) { + const char *prev = line; + // is next token empty? + if (ulas_tok(&ulas.tok, &line, n) == 0 || + strnlen(ulas.tok.buf, ulas.tok.maxlen) == 0) { + ulas_asmlst(start, outbuf, towrite); + return 0; + } + line = prev; + } else { + // start over for the next step... + line = start; + } + int nextwrite = ulas_asminstr(outbuf, ULAS_OUTBUFMAX, &line, n); if (nextwrite == -1) { ULASERR("Unable to assemble instruction\n"); diff --git a/tests/t0.s b/tests/t0.s index be28504..823a6b6 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -69,6 +69,6 @@ rlc c rlc [hl] - +label: bit 0, d bit 0, [hl]