From: Lukas Krickl Date: Mon, 20 Nov 2023 16:17:56 +0000 (+0100) Subject: WIP: instructions X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=a3f86ef57d884cae3e227a1d6f866bb7eed7adb7;p=ulas%2F.git WIP: instructions --- diff --git a/include/ulas.h b/include/ulas.h index 98bf219..5feb5ab 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -7,6 +7,7 @@ #define ULAS_PATHMAX 4096 #define ULAS_LINEMAX 4096 +#define ULAS_OUTBUFMAX 64 #define ULAS_MACROPARAMMAX 9 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) @@ -147,6 +148,9 @@ struct ulas { // internal counter // used whenever a new unique number might be needed int icntr; + + FILE *verbout; + FILE *symsout; }; extern struct ulas ulas; diff --git a/src/ulas.c b/src/ulas.c index 6f402f5..451968d 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1303,18 +1303,26 @@ int ulas_intexpr(const char **line, unsigned long n, int *rc) { return ulas_intexpreval(expr, rc); } -int ulas_asminstr(FILE *dst, const char *line, unsigned long n) { +int ulas_asmimisc(FILE *dst, const char *line, unsigned long n) {} + +// 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, + unsigned long n) { int rc = 0; return rc; } 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]; + memset(outbuf, 0, ULAS_OUTBUFMAX); + long towrite = 0; + const char *start = line; int rc = 0; - fprintf(dst, "%s", line); - // read the first token and decide ulas_tok(&ulas.tok, &line, n); @@ -1358,13 +1366,22 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { } else { // is regular line in form of [label:] instruction ; comment - if (ulas_asminstr(dst, line, n) == -1) { + if ((towrite += ulas_asminstr(outbuf, ULAS_OUTBUFMAX, line, n)) == -1) { ULASERR("Unable to assemble instruction\n"); rc = -1; goto fail; } + + // TODO: place marker when a label was unresolved + // write down byte location in dst as well as line number in verbout so we + // can fix them later } + fwrite(outbuf, 1, towrite, dst); + + // TODO: verbose output
\tline + fprintf(dst, "%08X\t%s", ulas.address, start); + fail: return rc; }