IFDEF not working, or is it me?
Hello, assembler gurus,
what I wanted to achieve is a default clock frequency of 50MHz, being defined in the common include file.
But I wanted the possibility to override the setting in individual source files.
I want to put a statement like MHZ EQU 20, or MHZ EQU 4 in a source file.
In the include I put:
The assembler will not assemble if I don't have MHZ defined in the source.
But this is the·reason why I used the IFDEF statement. In case I didn't define MHZ I want FREQ 50_000_000 to be executed.
In case I defined MHZ, I want FREQ to be set according to the value of MHZ.
This would be fine.
But the assembler complains about the missing symbol MHZ in the IF MHZ = 20 line.
Why? The assembler is not supposed to assemble the lines between IFDEF MHZ and ELSE?
Bug? Or silly me?
what I wanted to achieve is a default clock frequency of 50MHz, being defined in the common include file.
But I wanted the possibility to override the setting in individual source files.
I want to put a statement like MHZ EQU 20, or MHZ EQU 4 in a source file.
In the include I put:
IFDEF MHZ IF MHZ = 20 FREQ 20_000_000 ENDIF ELSE FREQ 50_000_000 ENDIF
The assembler will not assemble if I don't have MHZ defined in the source.
But this is the·reason why I used the IFDEF statement. In case I didn't define MHZ I want FREQ 50_000_000 to be executed.
In case I defined MHZ, I want FREQ to be set according to the value of MHZ.
This would be fine.
But the assembler complains about the missing symbol MHZ in the IF MHZ = 20 line.
Why? The assembler is not supposed to assemble the lines between IFDEF MHZ and ELSE?
Bug? Or silly me?
Comments
Please post the entire program.
Besides that, it is not wise to redefine FREQ.
Instead, demand·that device and freq are set in the application file·
rather than an include file. Then also let define a symbol that represents
the freq so you can have several code sections based on frequency
in your include files. That way you control everything from the application
file.
regards peter
I dropped the idea by now.
But still the strange behaviour of the Assembler persists.
Here is a complete sample. Put it in a.src file and try:
mySym is not defined. The assembler should assemble inc $09, no?
Instead it complains about the line IF mySym<10 in the ELSE clause, which should not be assembled at all, when mySym is not defined.
Also, mySym must be defined BEFORE the IFDEF statement. (That's ok, as long if you know it). But it is NOT alright, that any expression in a conditionally excluded part of the code is evaluated somehow and cause an error which stops the assembly.
This one is ok. No error. If storage is not defined, ds 2 is assembled. The else clause is not evaluated and there is no complaining about storage not being defined.
This one is not ok:
The IF storage = 0 statement will be evaluated somehow and cause the assembly to fail.
But this works
The if .. else .. endif works for sure. I use that frequently.
regards peter
Nevertheless, somebody who is responsible for SASM should read that and take in account that there is a leeettle bug in the assembler.
Thanks, Peter, for caring for my problem.
but we couldn't make it work. I used the above trick but with
a compiler variable. And I think that works.
Load the attached program and view list.
It should generate:
@pjv,
This is what you were after, right?
I have set aside a fixed area for the jumptable so it does require two compilations
if you want to trim that area so no codespace is wasted. The first compilation
will give you the address to be used instead of org $100 (= jmpentry value).
regards peter