diff --git a/src/assembler.c b/src/assembler.c index 48b6e72..34d6b41 100644 --- a/src/assembler.c +++ b/src/assembler.c @@ -263,11 +263,11 @@ walktoken(char *w) if(findopcode(w) || scmp(w, "BRK", 4)) return 1; switch(w[0]) { - case '=': return 4; /* STR helper (lit addr-hb addr-lb str) */ - case '~': return 4; /* LDR helper (lit addr-hb addr-lb ldr) */ - case ',': return 3; /* lit2 addr-hb addr-lb */ - case '.': return 2; /* addr-hb addr-lb */ - case '^': return 2; /* Relative jump: lit addr-offset */ + case '=': return 4 - (findlabeladdr(w + 1) < 0x0100); /* POK/STR helper (lit addr(1/2) str) */ + case '~': return 4 - (findlabeladdr(w + 1) < 0x0100); /* PEK/LDR helper (lit addr(1/2) ldr) */ + case ',': return 3; /* lit2 addr-hb addr-lb */ + case '.': return 2; /* addr-hb addr-lb */ + case '^': return 2; /* Relative jump: lit addr-offset */ case '#': return (slen(w + 1) == 2 ? 2 : 3); } if((m = findmacro(w))) { @@ -298,15 +298,25 @@ parsetoken(char *w) } else if(w[0] == '=' && (l = findlabel(w + 1))) { if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) return error("Invalid store helper", w); - pushshort(findlabeladdr(w + 1), 1); - pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0); + if(findlabeladdr(w + 1) < 0x0100) { + pushbyte(findlabeladdr(w + 1), 1); + pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR" : "POK"), 0); + } else { + pushshort(findlabeladdr(w + 1), 1); + pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0); + } l->refs++; return 1; } else if(w[0] == '~' && (l = findlabel(w + 1))) { if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) return error("Invalid load helper", w); - pushshort(findlabeladdr(w + 1), 1); - pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0); + if(findlabeladdr(w + 1) < 0x0100) { + pushbyte(findlabeladdr(w + 1), 1); + pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR" : "PEK"), 0); + } else { + pushshort(findlabeladdr(w + 1), 1); + pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0); + } l->refs++; return 1; } else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {