<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ARM: asm variable initialization</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/33033/arm-asm-variable-initialization</link><description> 
Hi 

 
Im using a STM32F429ZI and have the folowing problem: 

 
In my assembler program i initialize the following
variables: 

 
 AREA myVars, DATA, READWRITE

op1_table DCW 0x0001, 0x0017, 0xffff, 0x73a4, 0x43cc, 0xe372, 0xdd22, 0x7fff
op2_table</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/140733?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 04:48:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f5600dc4-f4ae-4078-8b44-7b3714c15825</guid><dc:creator>Stephan Feurer</dc:creator><description>&lt;p&gt;&lt;p&gt;
I guess i solved my initial problem...&lt;/p&gt;

&lt;pre&gt;
                AREA myVars, DATA, READWRITE

op1_table       DCW     0x0001, 0x0017, 0xffff, 0x73a4, 0x43cc, 0xe372, 0xdd22, 0x7fff
op2_table       DCW     0xffff, 0x0004, 0xffff, 0x4c28, 0xc3bf, 0x0234, 0xbcde, 0x7fff
&lt;/pre&gt;

&lt;p&gt;
What am i missing?&lt;/p&gt;

&lt;p&gt;
Answer:&lt;br /&gt;
Constants go into &amp;quot;READONLY&amp;quot;&lt;/p&gt;

&lt;pre&gt;
                AREA myVars, DATA, &lt;b&gt;READONLY&lt;/b&gt;

op1_table       DCW     0x0001, 0x0017, 0xffff, 0x73a4, 0x43cc, 0xe372, 0xdd22, 0x7fff
op2_table       DCW     0xffff, 0x0004, 0xffff, 0x4c28, 0xc3bf, 0x0234, 0xbcde, 0x7fff
&lt;/pre&gt;

&lt;p&gt;
Thanks Per after all you pointed me in the right direction. I
probably should have posted the original code and not this (hideous)
example trying to write to a constant...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/137140?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 03:59:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c6a8e06c-2ec1-4d70-876f-84a49d2c9685</guid><dc:creator>Stephan Feurer</dc:creator><description>&lt;p&gt;&lt;p&gt;
1) I&amp;#39;m using the debugger, this program never runs on the uc
standalone.&lt;/p&gt;

&lt;p&gt;
2) Why does it work on the 8051 or the c167 (with Keil)?&lt;/p&gt;

&lt;p&gt;
3) What is the difference between &lt;i&gt;DCD&lt;/i&gt; and &lt;i&gt;SPACE&lt;/i&gt;?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/128613?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 02:30:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:319db81b-a2fd-4ac8-82a1-4610175b416e</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
AREA is a directive for the assembler. It doesn&amp;#39;t mean anything
for the processor.&lt;/p&gt;

&lt;p&gt;
The processor - the physical hardware - can not have any magic
that makes RAM initialized with content when the processor wakes from
a reset. It is 100% up to the program that starts running to give
content to RAM.&lt;/p&gt;

&lt;p&gt;
That is one of many things that the CRTL startup code performs. If
you don&amp;#39;t use C then it&amp;#39;s something you must do.&lt;/p&gt;

&lt;p&gt;
The linker can produce a shadow-copy of initial RAM data in flash
- but the linker runs on your PC. It&amp;#39;s still the program that gets
downloaded into the microcontroller that must contain code to take
the contents of that shadow-copy and place in RAM.&lt;/p&gt;

&lt;p&gt;
It is only when you do debugging and run programs in RAM, that you
can have the download code place not just code but also variable data
into the RAM. No such thing can happen when you run a processor
stand-alone, so it just starts up from a reset and goes hunting for a
program in the flash.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/128622?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 02:26:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dd590333-cbb6-49ba-9f4b-4debafc7ada6</guid><dc:creator>Stephan Feurer</dc:creator><description>&lt;p&gt;&lt;pre&gt;
The DCW directive allocates one or more halfwords of memory, aligned on two-byte boundaries,
and defines the initial runtime contents of the memory. DCWU is the same, except that the memory
alignment is arbitrary.
&lt;/pre&gt;

&lt;p&gt;
from &lt;i&gt;armasm User Guide&lt;/i&gt; (version 5.04)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/117569?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 02:20:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1b9340c8-173e-43ec-aebc-0f773e206883</guid><dc:creator>Stephan Feurer</dc:creator><description>&lt;p&gt;&lt;p&gt;
1) Thats what the &lt;i&gt;DCx&lt;/i&gt; directive is for (at least in my
mind). It works exactly this way on the 8051, the C167 or the
186.&lt;/p&gt;

&lt;p&gt;
2) Doesn&amp;#39;t the &lt;i&gt;AREA myVars, DATA, READWRITE&lt;/i&gt; section copy
the variables i defined into the RAM? -&amp;gt; Again if not, whats the
point of the &lt;i&gt;DCx&lt;/i&gt;?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/107729?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 02:09:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f8f2d183-502b-45ec-9791-54c3945e0aa4</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
How do you think that data moves from flash to RAM when the
processor starts running a program? Can there be any possible way for
the data to jump into RAM unless the program contains some code that
performs that task?&lt;/p&gt;

&lt;p&gt;
Note that the directives don&amp;#39;t care about the persistance of the
memory region - so constants in flash can store data without need for
any runtime help. Initialized variables in RAM requires runtime help
to get their values - either explicit assigns or code that copies the
values from flash into RAM.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/81940?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 02:00:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4df91b8a-848d-43ae-ad78-826d79ca4445</guid><dc:creator>Stephan Feurer</dc:creator><description>&lt;p&gt;&lt;p&gt;
But that doesn&amp;#39;t fix my problem. I mean i could just use the
&lt;i&gt;SPACE&lt;/i&gt; directive and initialize the memory with &lt;i&gt;LDR/STR&lt;/i&gt;,
but then: whats the point about the &lt;i&gt;DCx&lt;/i&gt; directives?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM: asm variable initialization</title><link>https://community.arm.com/thread/68713?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2014 01:52:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ced3b506-f275-4927-b6ba-b1dcf4aaf913</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Note that the C example makes use of a function within the C
runtime library that will copy initial values from flash into RAM,
and zero-initialize the rest of the RAM before main() gets
called.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>