Browse code

Fixed issue with label length in pass2

neauoire authored on 21/03/2021 17:38:46
Showing 2 changed files
... ...
@@ -29,7 +29,7 @@ typedef struct {
29 29
 typedef struct {
30 30
 	char name[64];
31 31
 	Uint8 refs, maps;
32
-	Uint16 addr;
32
+	Uint16 addr, len;
33 33
 	Map map[16];
34 34
 } Label;
35 35
 
... ...
@@ -236,7 +236,8 @@ makevariable(char *name, Uint16 *addr, FILE *f)
236 236
 		if(word[0] == '}') break;
237 237
 		scpy(word, l->map[l->maps].name, 64);
238 238
 		fscanf(f, "%u", &l->map[l->maps].size);
239
-		*addr += l->map[l->maps++].size;
239
+		*addr += l->map[l->maps].size;
240
+		l->len += l->map[l->maps++].size;
240 241
 	}
241 242
 	return 1;
242 243
 }
... ...
@@ -384,11 +385,14 @@ pass2(FILE *f)
384 385
 	char w[64], scope[64], subw[64];
385 386
 	printf("Pass 2\n");
386 387
 	while(fscanf(f, "%s", w) == 1) {
387
-		if(w[0] == ';') continue;
388 388
 		if(w[0] == '$') continue;
389 389
 		if(w[0] == '%') continue;
390 390
 		if(skipblock(w, &ccmnt, '(', ')')) continue;
391 391
 		if(skipblock(w, &ctemplate, '{', '}')) continue;
392
+		if(w[0] == ';') {
393
+			p.ptr += findlabel(w + 1)->len;
394
+			continue;
395
+		}
392 396
 		if(w[0] == '|') {
393 397
 			p.ptr = shex(w + 1);
394 398
 			continue;
... ...
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
20 20
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 21
 
22 22
 # run
23
-./bin/assembler projects/software/nasu.usm bin/boot.rom
23
+./bin/assembler projects/software/noodle.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom