Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFNDEF directive is maybe broken #32

Open
ghost opened this issue Jan 31, 2022 · 1 comment
Open

IFNDEF directive is maybe broken #32

ghost opened this issue Jan 31, 2022 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Jan 31, 2022

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.

@freem freem added the bug label Jan 31, 2022
@ghost
Copy link
Author

ghost commented Jan 31, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant