Question about asm6 if else directive

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Question about asm6 if else directive
by on (#183294)
Hello!

I googled and read the asm6 loopy's readme but I couldn't find an answer how to correctly use the IF ELSE directive.
Code:
...
;define variable
updateDirection = $45
...

IF updateDirection = 1
   .include "updateUp.asm"
ELSEIF updateDirection = 2
   .include "updateDown.asm"
ENDIF


I'm using fceux hex editor for debugging and I can see the updateDirection value set correctly. But it will never execute the update code.

If I do it without the ELSE IF directive it works correctly.
Code:
   LDA updateDirection
   CMP #$01
   BNE SetDownRender
SetUpRender:
   .include "updateUp.asm"
   JMP EndSetUp
SetDownRender:
   .include "updateDown.asm"
EndSetUp:


I guess I could keep using the old code but I really like the IF ELSE more because it makes reading the code much easier.
I have a feeling it's comparing the updateDirection addresses not the values stored at updateDirection but I have no idea how to fix it.

Any help is appreciated :)
Re: Question about asm6 if else directive
by on (#183295)
The directive doesn't do what you think it does. It's a compile-time directive, which doesn't produce any code by itself, so your example was actually equivalent to this:
Code:
IF $45 = 1
   .include "updateUp.asm"
ELSEIF $45 = 2
   .include "updateDown.asm"
ENDIF
Re: Question about asm6 if else directive
by on (#183296)
Since $45 isn't equal to 1 or 2 it was actually equivalent to this:
Code:




;)
Re: Question about asm6 if else directive
by on (#183298)
Aha, no wonder then :lol:

Thanks guys!
Re: Question about asm6 if else directive
by on (#183300)
FYI: For ca65 (cc65) there's a set of macros which enables functionality similar to what you were expecting: http://mynesdev.blogspot.com/2012/10/ca ... again.html

(I'm not sure if the above link is to the latest version.)

There's also NESHLA: http://neshla.sourceforge.net/conditional/index.html#if
Re: Question about asm6 if else directive
by on (#183304)
Looks like NESHLA is exactly what I wanted :)
I'm definitely going to check it out.

Thanks again!
Re: Question about asm6 if else directive
by on (#183334)
It's be nice if NESHLA was a preprocessor instead of an assembler, so you could use it with assemblers.