Fixed issue with label length in pass2

This commit is contained in:
neauoire 2021-03-21 10:38:46 -07:00
parent 5610b9eb77
commit f4423ad629
2 changed files with 8 additions and 4 deletions

View File

@ -29,7 +29,7 @@ typedef struct {
typedef struct {
char name[64];
Uint8 refs, maps;
Uint16 addr;
Uint16 addr, len;
Map map[16];
} Label;
@ -236,7 +236,8 @@ makevariable(char *name, Uint16 *addr, FILE *f)
if(word[0] == '}') break;
scpy(word, l->map[l->maps].name, 64);
fscanf(f, "%u", &l->map[l->maps].size);
*addr += l->map[l->maps++].size;
*addr += l->map[l->maps].size;
l->len += l->map[l->maps++].size;
}
return 1;
}
@ -384,11 +385,14 @@ pass2(FILE *f)
char w[64], scope[64], subw[64];
printf("Pass 2\n");
while(fscanf(f, "%s", w) == 1) {
if(w[0] == ';') continue;
if(w[0] == '$') continue;
if(w[0] == '%') continue;
if(skipblock(w, &ccmnt, '(', ')')) continue;
if(skipblock(w, &ctemplate, '{', '}')) continue;
if(w[0] == ';') {
p.ptr += findlabel(w + 1)->len;
continue;
}
if(w[0] == '|') {
p.ptr = shex(w + 1);
continue;

View File

@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run
./bin/assembler projects/software/nasu.usm bin/boot.rom
./bin/assembler projects/software/noodle.usm bin/boot.rom
./bin/emulator bin/boot.rom