Moved label code to asmline
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Nov 2023 08:23:52 +0000 (09:23 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Nov 2023 08:23:52 +0000 (09:23 +0100)
src/ulas.c
tests/t0.s

index bdec825ea07db4009f0a11743126da22b005cd1f..751220bdcfaa788e7fcedadc10e4934425bbfd51 100644 (file)
@@ -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");
index be28504e837a6b2e094d26284546ef53e90200a8..823a6b685d52b750153611f0f1a5449fc13366ca 100644 (file)
@@ -69,6 +69,6 @@
 
   rlc c
   rlc [hl]
-
+label:
   bit 0, d
   bit 0, [hl]