From a13f56016d10edd1bdc76cadbb0f5f7fd11e0970 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 1 May 2023 22:13:54 +0100 Subject: Added equ to assembler To define constants. --- tr8as.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'tr8as.c') 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); } -- cgit v1.2.3