Skip to content

Commit

Permalink
a16: cleanup and bugfixes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
swetland committed Apr 5, 2012
1 parent 6767682 commit 66c727b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
27 changes: 10 additions & 17 deletions a16.c
Expand Up @@ -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[] = {
Expand All @@ -148,7 +148,7 @@ static const char *tnames[] = {
"JSR",
"POP", "PEEK", "PUSH", "SP", "PC", "O",
"WORD",
",", "[", "]", ":",
",", "[", "]", ":", "+",
"<STRING>", "<NUMBER>", "<EOF>",
};
static const char *rnames[] = {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -251,25 +253,16 @@ 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:
image[PC++] = tnumber;
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/example.s
Expand Up @@ -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 [*]
Expand Down

0 comments on commit 66c727b

Please sign in to comment.