Welcome to the Zilog forum!
Go to bottomPage: 12
TOPIC:
#1101
Re:Information exchange between .c source and .asm 4 Months, 2 Weeks ago Karma: 0
Great help, mr, thank you.

Regarding my initial question, I have found out that it is in fact possible to define symbols in C that
can be used in asm, like this:

#define PARTICULAR_OPTION 1

#if PARTICULAR_OPTION
#pragma asm "PARTICULAR_OPTION equ 1"
#else
#pragma asm "PARTICULAR_OPTION equ 0"
#endif
#pragma asm "xdef PARTICULAR_OPTION"

Then in asm

xref PARTICULAR_OPTION
ld r0,#PARTICULAR_OPTION

To get true conditional assembly I would prefer this method:

#define PARTICULAR_OPTION 1

#if PARTICULAR_OPTION
#pragma asm "PARTICULAR_OPTION" // becomes a program label
#pragma asm "xdef PARTICULAR_OPTION"
#endif

and in asm:

xref PARTICULAR_OPTION

ifdef PARTICULAR_OPTION
ld r0,#1234
else
ld r0,#5678
endif

To my great disappointment, however, the ifdef directive does not work properly on the assembler,
because it treats any xref'ed symbol as being defined, so the above will always end up with r0 = 1234.

With my current project settings, C puts variables in a segment called FAR_BSS. So I did this in asm:

segment FAR_BSS
_my_asm_variable ds 4
xdef _my_asm_variable

Then in C:

extern unsigned int my_asm_variable;

After rebuild, this variable had the same address in the asm listing and the C listing.

It works in the reverse direction too. In C:

static unsigned int my_c_variable;
#pragma asm "xdef _my_c_variable"

and in asm:

xref _my_c_variable
ld r0,_my_c_variable

They got the same address also.
Mikael Ponten (User)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#1102
Re:Information exchange between .c source and .asm 4 Months, 2 Weeks ago Karma: 0
Glad to help.

I appreciate seeing your example with #pragma asm. I hadn't thought of that one.
mr (User)
Senior Boarder
Posts: 41
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12