aboutsummaryrefslogtreecommitdiff
path: root/tr8as.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-01 22:13:54 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-01 22:13:54 +0100
commita13f56016d10edd1bdc76cadbb0f5f7fd11e0970 (patch)
tree0a9b244663f64f69f58715902aa878294fdfc07a /tr8as.c
parent5c763c23144b04b50e804d4ac7b6504b8f1fcaf6 (diff)
downloadtr8vm-a13f56016d10edd1bdc76cadbb0f5f7fd11e0970.tar.gz
tr8vm-a13f56016d10edd1bdc76cadbb0f5f7fd11e0970.zip
Added equ to assembler
To define constants.
Diffstat (limited to 'tr8as.c')
-rw-r--r--tr8as.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/tr8as.c b/tr8as.c
index e450288..6c9bd27 100644
--- a/tr8as.c
+++ b/tr8as.c
@@ -232,6 +232,15 @@ static uint8_t new_label(As *as, char *word)
return 1;
}
+static uint8_t new_label_imm(As *as, char *word, uint16_t imm)
+{
+ if (!new_label(as, word))
+ return 1;
+
+ as->labels[as->lcnt - 1].addr = imm;
+ return 1;
+}
+
static uint8_t new_ref(As *as, char *word, uint16_t mask, uint16_t addr)
{
Mod mod = ModNone;
@@ -340,6 +349,30 @@ static uint8_t parse_org(As *as, char *c)
return 1;
}
+static uint8_t parse_equ(As *as, char *c)
+{
+ char label[MAX_ID + 1];
+ char word[MAX_ID + 1];
+ char *pt;
+ uint8_t wlen;
+ uint16_t imm;
+
+ /* .equ label imm */
+
+ pt = next_word(c, label, &wlen);
+ if (wlen == 0)
+ return error_l("Syntax error", &as->loc, "expected label");
+
+ next_word(pt, word, &wlen);
+ if (wlen == 0)
+ return error_l("Syntax error", &as->loc, "expected immediate");
+
+ if (next_imm(word, &imm))
+ return error_l("Syntax error", &as->loc, word);
+
+ return new_label_imm(as, label, imm);
+}
+
static uint8_t parse_db(As *as, char *c)
{
char word[MAX_ID + 1];
@@ -1213,6 +1246,7 @@ static uint8_t parse_ld(As *as, char *c)
static InstParse insts[] = {
{ ".org", parse_org },
+ { ".equ", parse_equ },
{ ".db", parse_db },
{ ".dw", parse_dw },
{ "halt", parse_halt },
@@ -1287,7 +1321,6 @@ static uint8_t parse(As *as, char *c)
for (i = 0; insts[i].parse; i++)
if (!strcasecmp(insts[i].id, word))
return insts[i].parse(as, pt);
- printf("NOPE %s\n", word);
return error_l("Parse error", &as->loc, word);
}