Assembly directives

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Assembly directives

1,042 次查看
mouka
Contributor II

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!!

标签 (1)
0 项奖励
回复
1 回复

722 次查看
CompilerGuru
NXP Employee
NXP Employee

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

0 项奖励
回复