commit 66c727bc6513916bbff33298e00600d39844d885
parent 67676821b271e9d3d4605914067704734356e05c
Author: Brian Swetland <swetland@frotz.net>
Date: Wed, 4 Apr 2012 21:52:44 -0700
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
Diffstat:
2 files changed, 11 insertions(+), 18 deletions(-)
diff --git 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",
- ",", "[", "]", ":",
+ ",", "[", "]", ":", "+",
"<STRING>", "<NUMBER>", "<EOF>",
};
static const char *rnames[] = {
@@ -172,13 +172,13 @@ nextline:
}
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
@@ -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 [*]