From: Lukas Krickl Date: Sun, 24 Dec 2023 17:33:24 +0000 (+0100) Subject: Added counter symbol naming to .rep X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=3fc005ada833407047fb1f0860bb6dd07708f360;p=ulas%2F.git Added counter symbol naming to .rep --- diff --git a/src/ulas.c b/src/ulas.c index 0a11ad1..dffea89 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -2585,6 +2585,26 @@ int ulas_asmdirchr(FILE *dst, const char **line, unsigned long n, int *rc) { } int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { + char name[ULAS_SYMNAMEMAX]; + ulas_tok(&ulas.tok, line, n); + if (!ulas_isname(ulas.tok.buf, ulas.tok.maxlen)) { + ULASERR("Unexpected token '%s'\n", ulas.tok.buf); + return -1; + } + strncpy(name, ulas.tok.buf, ULAS_SYMNAMEMAX); + + // consume , + ulas_tok(&ulas.tok, line, n); + if (strncmp(ulas.tok.buf, ",", ulas.tok.maxlen) != 0) { + ULASERR("Unexpected token '%s'. Expected ','\n", ulas.tok.buf); + return -1; + } + + union ulas_val val = {0}; + val.intv = 0; + struct ulas_tok tok = {ULAS_INT, val}; + ulas_symbolset(name, ulas.scope, tok, 0); + int repval = 0; int rc = 0; @@ -2609,6 +2629,8 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { unsigned long argline_len = strlen(*line); for (int i = 0; i < repval; i += step) { + tok.val.intv = i; + ulas_symbolset(name, ulas.scope, tok, 0); rc = ulas_asmline(dst, src, *line, argline_len); if (rc == -1) { break; diff --git a/tests/t0.bin b/tests/t0.bin index d480d73..ec638b9 100644 Binary files a/tests/t0.bin and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index 296c6fd..17e0ab0 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -131,4 +131,5 @@ l3: .db 1 .db 1, 2, 3 .chr 01233213 -.rep 6, 2, halt +.rep repc, 6, 2, ld a, repc +.rep repc, 6, 1, ld a, repc