I am trying to declare variables and intialize them in assembly.
here's what I have tested so far:
variableName: dc.b $xx ; This declares a named constant. So my code in theory cannot change it
variableName: ds.b 1 ; This creates a variable but it's uninitialized
How do I create an initialized variable?
I know I could write a code fragment that initializes my uninitialized variables, but there should be an easier way.
I used to do:
variableName: db $xx ; This declares a variable and initializes it with $xx
Thanks for your help!!
I assume you are using the C startup code to initialize the variable. Without the C startup code, the assembly code to initialize the variables has to be provided.
When using the C startup code, the dc.b will work. The key is to place the dc.b's into a section which ends up in the prm file in a READ_WRITE placement.
E.g.
MY_VAR_SEG: SECTION
variableName: dc.b $ab
And in the prm file, explicitly list MY_VAR_SEG in a READ_WRITE placement. Without the explicit placement in the prm file, the dc.b will end up in flash.
Note that the same works for C objects too. When C consts are placed in a READ_WRITE placement they are initialized by the startup code. On the other side, when (initialized) C variables are placed in a READ_ONLY placement they are defined at download time (say typically end up in flash).
Daniel