WIP: address labels
authorLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 15:21:25 +0000 (16:21 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 2 Dec 2023 15:21:25 +0000 (16:21 +0100)
src/ulas.c
tests/t0.s

index 854eebc6898da9a216aef258177d55029e401726..24376f25109f4ce16fbe829705b6b930bf0ae2aa 100644 (file)
@@ -1187,7 +1187,10 @@ void ulas_symbufclear(struct ulas_symbuf *sb) {
   sb->len = 0;
 }
 
-void ulas_symbuffree(struct ulas_symbuf *sb) { free(sb->buf); }
+void ulas_symbuffree(struct ulas_symbuf *sb) {
+  ulas_symbufclear(sb);
+  free(sb->buf);
+}
 
 /**
  * Assembly step
@@ -2072,13 +2075,16 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) {
     // is it a label?
     if (ulas_islabelname(ulas.tok.buf, strlen(ulas.tok.buf))) {
       const char *prev = line;
+      struct ulas_tok label_tok = {ULAS_INT, {ulas.address}};
+      ulas_symbolset(ulas.tok.buf, -1, label_tok, 1);
+
       // 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;
       }
-      // ulas_symbolset(ulas.tok.buf, -1,
+
       line = prev;
     } else {
       // start over for the next step...
index 823a6b685d52b750153611f0f1a5449fc13366ca..102f333ffe22b1c164b8dcf42c9ab619d366899d 100644 (file)
@@ -69,6 +69,8 @@
 
   rlc c
   rlc [hl]
-label:
+l1:
   bit 0, d
   bit 0, [hl]
+
+  ; ld bc, l1 + 1