From: Lukas Krickl Date: Wed, 22 Nov 2023 07:29:00 +0000 (+0100) Subject: WIP: asm load instruction X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=0ecb0d48210261e82807e429aa25b05eafa971c2;p=ulas%2F.git WIP: asm load instruction --- diff --git a/src/ulas.c b/src/ulas.c index 9c9bcfc..5409f15 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1392,28 +1392,29 @@ const char *ulas_asmregstr(enum ulas_asmregs reg) { return n; \ } -// parses ld r8, r8 -int ulas_ldr8r8(char *dst, unsigned long max, char *name, int base, - enum ulas_asmregs regleft) { - const char *left = ulas_asmregstr(regleft); - if (strncmp(ulas.tok.buf, (name), ulas.tok.maxlen) != 0) { +// parses r8, r8 +int ulas_ld(char *dst, unsigned long max, const char **line, unsigned long n) { + if (strncmp(ulas.tok.buf, "ld", ulas.tok.maxlen) != 0) { return 0; } - return 1; + // decide which load instruction we have here + + // if nothing matches... we have an error at this point + return -1; } // assembles an instruction, writes bytes into dst // returns bytes written or -1 on error -int ulas_asminstr(char *dst, unsigned long max, const char *line, +int ulas_asminstr(char *dst, unsigned long max, const char **line, unsigned long n) { - + char *start = *line; if (max < 4) { ULASPANIC("Instruction buffer is too small!"); return -1; } - if (ulas_tok(&ulas.tok, &line, n) == -1) { + if (ulas_tok(&ulas.tok, line, n) == -1) { ULASERR("Expected label or instruction\n"); return -1; } @@ -1421,6 +1422,8 @@ int ulas_asminstr(char *dst, unsigned long max, const char *line, // TODO: check for symbol token here... if so add it // and skip to the next token + int towrt = 0; + // misc / control ULAS_STATICINSTR("nop", 1, 0x00); ULAS_STATICINSTR("halt", 1, 0x76); @@ -1429,8 +1432,11 @@ int ulas_asminstr(char *dst, unsigned long max, const char *line, ULAS_STATICINSTR("ei", 1, 0xFB); // 8 bit loads + if ((towrt = ulas_ld(dst, max, line, n)) > 0) { + return towrt; + } - ULASERR("Invalid instruction '%s'\n", ulas.tok.buf); + ULASERR("Invalid instruction '%s'\n", start); return -1; } @@ -1518,8 +1524,10 @@ 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 - if ((towrite += ulas_asminstr(outbuf, ULAS_OUTBUFMAX, start, n)) == -1) { + if ((towrite += ulas_asminstr(outbuf, ULAS_OUTBUFMAX, &line, n)) == -1) { ULASERR("Unable to assemble instruction\n"); rc = -1; goto fail;