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. --- example.asm | 8 ++++++-- tr8as.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/example.asm b/example.asm index 7d69611..694501c 100644 --- a/example.asm +++ b/example.asm @@ -3,10 +3,14 @@ ; .org 0 +; address of the frame interrupt vector +.equ INT_VECT 0xff00 + ; setup an int handler so we ; can use the frame int to sync - ld a, 0xff - ld x, 0 + ld a, >INT_VECT + ld x, 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