This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Asm/C preprocessor does not like Long Constants.

Hi,
I have a problem with the way your preprocessor works. This problem occurs in both assembly and in C.
The reason we started trying to do this in C was that the assembler had a problem and while it accepted the code, did not produce the correct constant. It truncated the long constant to a 16 bit value and then divided. This produced a zero and messed up the program.

When we originally wrote

CLOCK_PERIOD_32K_100 equ (3052)
DELAY_20_MS equ 2000000 / CLOCK_PERIOD_32K_100

We expected a value of about 655 from the preprocessor. This would fit into a 16 bit value and work well. We got zero or some other unexpected value. So we moved it to C.

#define CLOCK_PERIOD_32K_100 ((long)(3052L))
#define DELAY_1_MS ((USHORT)(100000L / CLOCK_PERIOD_32K_100))
#define DELAY_2_MS 200000 / CLOCK_PERIOD_32K_100
#define DELAY_20_MS ((USHORT)((long)(2000000L) / CLOCK_PERIOD_32K_100)) ;this is about 655 counts

When I used the above in an asm file, the assembler did not like constants with L on the end, and complained that a paren was missing. Not really up to the usual C standard for constants. It did not divide, just complained. And Casts will not work well.

So what should we do?
If nothing but go through the math my self and post that constant (say 655 for the above) to the #define, we will do what we must, and this post will be a warning for anyone trying to use the preprocessor in the same way.
John "Sean" Cleary
Sean

0