From 66c727bc6513916bbff33298e00600d39844d885 Mon Sep 17 00:00:00 2001 From: Brian Swetland Date: Wed, 4 Apr 2012 21:52:44 -0700 Subject: [PATCH] a16: cleanup and bugfixes - don't use a second word for literal arguments 0x00-0x1f - allow the [imm + reg] form as well as [imm, reg] - disallow [reg,imm] or [reg+imm] forms for the time being - return example.s to original syntax --- a16.c | 27 ++++++++++----------------- tests/example.s | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/a16.c b/a16.c index 02173b7..27307fd 100644 --- a/a16.c +++ b/a16.c @@ -138,7 +138,7 @@ enum tokens { tJSR, tPOP, tPEEK, tPUSH, tSP, tPC, tO, tWORD, - tCOMMA, tOBRACK, tCBRACK, tCOLON, + tCOMMA, tOBRACK, tCBRACK, tCOLON, tPLUS, tSTRING, tNUMBER, tEOF, }; static const char *tnames[] = { @@ -148,7 +148,7 @@ static const char *tnames[] = { "JSR", "POP", "PEEK", "PUSH", "SP", "PC", "O", "WORD", - ",", "[", "]", ":", + ",", "[", "]", ":", "+", "", "", "", }; static const char *rnames[] = { @@ -172,13 +172,13 @@ int _next(void) { } switch ((c = *lineptr++)) { case ',': return tCOMMA; + case '+': return tPLUS; case '[': return tOBRACK; case ']': return tCBRACK; case ':': return tCOLON; case '/': case ';': *lineptr = 0; goto nextline; default: - if (isdigit(c) || - (((c == '+') || (c == '-')) && isdigit(*lineptr))) { + if (isdigit(c) || ((c == '-') && isdigit(*lineptr))) { tnumber = strtoul(lineptr-1, &lineptr, 0); return tNUMBER; } @@ -223,7 +223,7 @@ void assemble_imm_or_label(void) { } int assemble_operand(void) { - int n; + u16 n; next(); switch (token) { case tA: case tB: case tC: case tX: @@ -236,6 +236,8 @@ int assemble_operand(void) { case tPC: return 0x1c; case tO: return 0x1d; case tNUMBER: + if (tnumber < 0x20) + return tnumber + 0x20; image[PC++] = tnumber; return 0x1f; case tSTRING: @@ -251,16 +253,8 @@ int assemble_operand(void) { case tA: case tB: case tC: case tX: case tY: case tZ: case tI: case tJ: n = token & 7; - next(); - if (token == tCBRACK) { - return n | 0x08; - } else if (token == tCOMMA) { - assemble_imm_or_label(); - expect(tCBRACK); - return n | 0x10; - } else { - die("invalid operand"); - } + expect(tCBRACK); + return n; case tSTRING: use_label(tstring, PC); case tNUMBER: @@ -268,8 +262,7 @@ int assemble_operand(void) { next(); if (token == tCBRACK) { return 0x1e; - } else if (token == tCOMMA) { - u16 n; + } else if ((token == tCOMMA) || (token == tPLUS)) { next(); if ((token >= tA) && (token <= tJ)) { n = 0x10 | (token & 7); diff --git a/tests/example.s b/tests/example.s index d17659d..f8cbfb4 100644 --- a/tests/example.s +++ b/tests/example.s @@ -12,7 +12,7 @@ SET I, 10 ; a861 SET A, 0x2000 ; 7c01 2000 :loop - SET [0x2000,I], [A] ; 2161 2000 + SET [0x2000+I], [A] ; 2161 2000 SUB I, 1 ; 8463 IFN I, 0 ; 806d SET PC, loop ; 7dc1 000d [*]