From 5a2819874f3a30b7bbd61d4443ec45f6ac93e910 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 5 Dec 2023 19:56:23 +0100 Subject: [PATCH] Added .str directive --- src/ulas.c | 26 +++++++++++++++++++++++++- tests/t0.bin | Bin 129 -> 139 bytes tests/t0.s | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ulas.c b/src/ulas.c index 44938ec..ea96dc8 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -2223,6 +2223,28 @@ int ulas_asmdirfill(FILE *dst, const char **line, unsigned long n, int *rc) { return written; } +int ulas_asmdirstr(FILE *dst, const char **line, unsigned long n, int *rc) { + // .str expr, expr, expr + struct ulas_tok t; + int written = 0; + memset(&t, 0, sizeof(t)); + + do { + char *s = ulas_strexpr(line, n, rc); + long len = strlen(s); + ulas_asmout(dst, s, len); + + written += len; + if (ulas_tok(&ulas.tok, line, n) > 0) { + t = ulas_totok(ulas.tok.buf, strnlen(ulas.tok.buf, ulas.tok.maxlen), rc); + } else { + break; + } + } while (*rc != -1 && t.type == ','); + + return written; +} + int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { // this buffer is written both to dst and to verbose output char outbuf[ULAS_OUTBUFMAX]; @@ -2283,8 +2305,10 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { case ULAS_ASMDIR_FILL: other_writes += ulas_asmdirfill(dst, &line, n, &rc); break; - case ULAS_ASMDIR_INCBIN: case ULAS_ASMDIR_STR: + other_writes += ulas_asmdirstr(dst, &line, n, &rc); + break; + case ULAS_ASMDIR_INCBIN: case ULAS_ASMDIR_PAD: // TODO: pad is the same as .fill n, $ - n case ULAS_ASMDIR_NONE: diff --git a/tests/t0.bin b/tests/t0.bin index 79fe45a9385690c4d6f3d0e952ac5ced9f170f2e..5f3faedb0e43472151f75f8091ef024132d022c2 100644 GIT binary patch delta 17 VcmZo<>}H(M$W@YBTw(|!i~uzG1`PlJ delta 6 NcmeBXY-F6!2ml840w4eY diff --git a/tests/t0.s b/tests/t0.s index 0faea94..f3999dc 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -91,3 +91,5 @@ l2: .fill 1, 0x180-$ ; fill until 0x180 nop .def str s2 = "Hello" + +.str "test1", "test2" -- 2.30.2