diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-01 22:13:54 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-01 22:13:54 +0100 |
commit | a13f56016d10edd1bdc76cadbb0f5f7fd11e0970 (patch) | |
tree | 0a9b244663f64f69f58715902aa878294fdfc07a | |
parent | 5c763c23144b04b50e804d4ac7b6504b8f1fcaf6 (diff) | |
download | tr8vm-a13f56016d10edd1bdc76cadbb0f5f7fd11e0970.tar.gz tr8vm-a13f56016d10edd1bdc76cadbb0f5f7fd11e0970.zip |
Added equ to assembler
To define constants.
-rw-r--r-- | example.asm | 8 | ||||
-rw-r--r-- | 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, <INT_VECT + ld b, <int_handler ld [a : x], b inc x @@ -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); } |