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

Using 'C' pre-processor with A51

Common C51 & A51 headers are very useful. However, there seems to be no way to write code that is conditional upon command line defines that works for both the compiler and the assembler. For example, if I define the symbol _DEBUG on the command line, I can write -

$if _DEBUG
  Size set 100
  ; ...
$else
  Size set 50
  ; ...
$endif

for A51, or -

#ifdef _DEBUG
  #define size 100
  // ...
#else
  #define size 50
  // ...
#endif

for C51.

However, it appears that there are two separate symbol tables, so it is not possible to use just the 'C' preprocessor macros. Neither is it possible to translate between them. The following results in _DEBUG always being defined to the 'C' preprocessor -

#ifdef __A51__
  $if _DEBUG
    #define _DEBUG
  $endif
#endif

#ifdef _DEBUG
  // ...
#endif

Presumably this is because the 'C' preprocessor makes the first pass, ignoring any A51 code.

This somewhat limits the usefullness of common headers. Does anybody know of any workarounds, other than pre-translating the code?

Parents
  • I just tried the following and it worked as expected:

    DEFS.H

    #define v1 100
    #define v2 200

    TEST.A51

    #include "defs.h"
    
    cseg at 0x1000
    	mov	A, #v1
    	mov	R0,#v2
    end

    When I assemble this file, I get the following listing.

    LOC  OBJ            LINE     SOURCE
    
                           1     ;#include "defs.h"
                    +1     2
                    +1     3
                    +1     4
                           5
                           6
    ----                   7     cseg at 0x1000
    1000 7464              8             mov     A, #100
    1002 78C8              9             mov     R0,#200
                          10     end

    This looks like what I expect.

    Jon

Reply
  • I just tried the following and it worked as expected:

    DEFS.H

    #define v1 100
    #define v2 200

    TEST.A51

    #include "defs.h"
    
    cseg at 0x1000
    	mov	A, #v1
    	mov	R0,#v2
    end

    When I assemble this file, I get the following listing.

    LOC  OBJ            LINE     SOURCE
    
                           1     ;#include "defs.h"
                    +1     2
                    +1     3
                    +1     4
                           5
                           6
    ----                   7     cseg at 0x1000
    1000 7464              8             mov     A, #100
    1002 78C8              9             mov     R0,#200
                          10     end

    This looks like what I expect.

    Jon

Children