This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Accessing C-defined Symbols from ASM code

Hi Forum Members:

This should be easy, but I have not figured out the correct syntax to allow my ASM code to use C-defined symbols.

My challenge is to allow SYMBOLS to be defined in C (for convenience) and used in both C and ASM (for ARM) from the single definition.  I seem to be having trouble making the ASM code use the #defined value from C.

Accessing C's "my_function" from ASM is no problem, but getting the constant value from C then using it in ASM as a constant value to load into register R0 is the problem I am having.

Any ideas for a solution would be much appreciated:

// ------------- C Code ---------------

#define C_SYMBOL  5   // define C-symbol to have value of 5

void my_function(int parameter_value) // process the given int value

{

switch (parameter_value) // decode given int value

{

C_SYMBOL:

// process my function value when parameter_value = 5

break;

// process other values as necessary

}

}

 

; --------------- ASM Code (ARM language) ------------

.global my_function ; this should allow ASM to find the C-function called "my_function"

.global C_SYMBOL ; this should allow ASM to get the value of 5 for C_SYMBOL

.text

.arm

start:

; some asm code goes here if necessary

MOV R0, #C_SYMBOL ; prepare value to pass to my_function via R0

BL my_function ; branch and link to my_function passing value in R0

; continue with asm code

.end

I get errors when I try this.  Maybe there are some missing "extern" or ".ref .def" directives. The errors are either "undefined" or will not allow #C_SYMBOL to be loaded into R0, I don't recall exactly what because I tried so many things to make this work but without success.

All suggestions appreciated.  I will try them tomorrow when I get back to the office.

Thanks,
Garry Anderson.