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.
Hello all,
I am trying to get the address of a variable declared in C and use it in an assembly routine. What is the proper syntax!? I can't seem to find it in the mixing C/Assem manual, other docs or on Google. Here is what I'm trying to do:
myCFile.c
unsigned int myCArray[3] = {0x0001,0x0002,0x0003}; //Say the Compiler assigned this array to start at mem address 0x8000
...
myASMFile.asm
.global myCArray
...
MOV &myCArray, R15
...
In this case the value '0x0001' is moved to R15. What is the proper syntax to get the value '0x8000' into R15!? Currently I am hardcoding it so I can move forward in dev. But there has to be a simple answer here....
Thanks in advance!
-Justin Reina
*I am using Code Composer Studio
Hi Justin,
I believe .global directive works to reference the address, but the .ref directive is probably more appropriate.... it identifies a symbol used in a module that is defined in another module.
Then I believe you would just deal with the address as a constant, such as:
MOV #(myCArray), R15
Hope that helps!
Dave H.
wouldn't you know it, that works. Dave you're awesome, thanks!
Additional
Two notes on this access in the event someone else runs by this thread someday.
Valid Syntax for CCS:
Thanks!
-Justin Reina
Just for clarifiation..
The originally used operator & refers to an indirect value. So the cpu was instructed to load the value that is at the address pointed to by the given reference. So since the reference was 0x8000, the cpu loaded the vaklue from memory address 0x8000, which was apparently 0x0001.
This is the opposite form the C notation, where x gives you the value of variable x (the value stored at the address referenced by the identifyer x) and &x gives you the value of the identifyer itself, which is the storage location of the variable.
In assembly, #x gives you the value of the symbol (this is the addrress of the variable etc.), while'&x gives you the content of the location where x points to. plain 'x' gives also the vcontent, but the generated code has a slightly different meaning. While '&x' refers to an absolute address, plain 'x' does not load form an absolute position, bu tfrom a position relative to the current program counter. (teh difference to the absolute position is calculated at linktime).
This is seldom used, but might be handy if you are writing relocatable code that has local constants.
Jens,
Thanks for that clarification, very useful and clear!!
-Justin Reina
*This isn't the first time I've found tremendous utility from your posts Jens. Thank you for all the help you given in this forum!!
**Attention** This is a public forum