freem / asm6f

A fork of loopy's ASM6, a 6502 assembler.
96 stars 24 forks source link

IFNDEF directive is maybe broken #32

Open ghost opened 2 years ago

ghost commented 2 years ago

I tried to do "header guards" by using the IFNDEF directive, but the file ends up not being included at all

Here's what I've done on the inc file:

.ifndef HEADER_NAME
  HEADER_NAME = 0
  ; code here
.endif

Then I have included the inc file in my main file using .include "incfile.inc" and it doesn't get included.

ghost commented 2 years ago

UPDATE: Actually the problem is a bit trickier to reproduce.

What was happening in my code was that I had created a label that was referenced before its declaration. Something like this:

.include "incfile.inc" ; the file gets included here

label1:
  jmp label2 ; label2 is not defined yet

label2: ; here label2 is defined
  ; code for label2 here

I assume the assembler supports this by reading the code multiple times. This might be happening because label1 was not assembled (due to not knowing label2 yet) and the assembler had to start over and assemble that part after knowing label2.

When starting over, the IFNDEF check does not pass, because it was defined already and so the assembler ignores that part, not including it in the binary.

The proof is that the code works normally if I declare the label before actually using it.