<?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>Asm programming</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26895/asm-programming</link><description> 
Hello 
Where can I find some example programs only in asm to be compiled
inder Keil MDK? 
I can&amp;#39;t compile simple programs as: 

 
STACK_TOP EQU 0x20002000 ; constant for SP starting value
 AREA |Header Code|, CODE
 DCD STACK_TOP ; Stack top
 DCD Start</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/142569?ContentTypeID=1</link><pubDate>Sat, 20 Feb 2010 07:26:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ec60328e-09b6-4036-a818-6d862d9a9c7c</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
I found the sollution. Probabely the program code was in reserver
region. I copied all startup code (all vector table) and now it is
working properly. I found it in dissasembled code. In all built in
projects the first instruction was in higher address than 0x18 in my
code.&lt;br /&gt;
Now I use build in startup file but I have to comment one line:&lt;/p&gt;

&lt;pre&gt;
 User Initial Stack &amp;amp; Heap

                IF      :DEF:__MICROLIB

                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit

                ELSE

; IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap

                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR

                ALIGN

                ENDIF
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
because i get following messages:&lt;br /&gt;
blinky.axf: Warning: L6665W: Neither Lib$$Request$$armlib
Lib$$Request$$cpplib defined, not searching ARM libraries.&lt;br /&gt;
blinky.axf: Error: L6218E: Undefined symbol __use_two_region_memory
(referred from startup_lpc17xx.o).&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/139482?ContentTypeID=1</link><pubDate>Sat, 20 Feb 2010 06:19:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3781f426-d2e2-44a1-a031-65c029180cc0</guid><dc:creator>Marcus Harnisch</dc:creator><description>&lt;p&gt;&lt;p&gt;
Gp F wrote:&lt;br /&gt;
&amp;gt; R3 contains an unaligned address&lt;/p&gt;

&lt;p&gt;
Really? The value in r3 is 0x2009C040. Looks aligned to me.&lt;/p&gt;

&lt;p&gt;
MOVW assigns the lower half-word and clears the upper. MOVT
assigns&lt;br /&gt;
the upper half-word. Easier to use here would be the pseudo&lt;br /&gt;
instruction&lt;/p&gt;

&lt;pre&gt;
MOV32 r3, #0x2009C040
&lt;/pre&gt;

&lt;p&gt;
Tamir wrote:&lt;br /&gt;
&amp;gt; in fact, STR is documented to have the ability to handle
unaligned&lt;br /&gt;
&amp;gt; accesses on ARM7 and Cortex M3 !&lt;/p&gt;

&lt;p&gt;
Depends on what is meant by &amp;quot;handle&amp;quot;. ARM7 has a rather creative
way&lt;br /&gt;
of dealing with unaligned accesses -- the results would be
unexpected&lt;br /&gt;
to most people who are unfamiliar with architecture details.&lt;/p&gt;

&lt;p&gt;
Cortex-M3 does handle unaligned accesses but not in all&lt;br /&gt;
situations. Check out the documentation.&lt;/p&gt;

&lt;p&gt;
--&lt;br /&gt;
Marcus&lt;br /&gt;
&lt;a href="http://www.doulos.com/arm/"&gt;http://www.doulos.com/arm/&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/144821?ContentTypeID=1</link><pubDate>Sat, 20 Feb 2010 05:50:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9a5854d2-438f-48f0-9f97-aac969629896</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
Finally I wrote a program which can be compiled in Keil:&lt;/p&gt;

&lt;pre&gt;
; &amp;lt;h&amp;gt; Stack Configuration
;   &amp;lt;o&amp;gt; Stack Size (in Bytes) &amp;lt;0x0-0xFFFFFFFF:8&amp;gt;
; &amp;lt;/h&amp;gt;

Stack_Size      EQU     0x00000200

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; &amp;lt;h&amp;gt; Heap Configuration
;   &amp;lt;o&amp;gt;  Heap Size (in Bytes) &amp;lt;0x0-0xFFFFFFFF:8&amp;gt;
; &amp;lt;/h&amp;gt;

Heap_Size       EQU     0x00000000

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

                PRESERVE8
                THUMB

; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors

__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler



                AREA    Program, CODE, READONLY

                                EXPORT Reset_Handler            ;Defines the program starting point

;Program start

Reset_Handler

                        MOV             R1, #0

                        MOVW    R3, #0xC040             ;P2.2, P2.3, P2.4, P2.5, and P2.6 function mode is located at FP2DIR (0&amp;Atilde;&amp;mdash;2009_C040).
                        MOVT    R3, #0x2009

                        MOVW    R2, #0x007C             ;P2.2  -&amp;gt; Bit[2] * P2.3  -&amp;gt; Bit[3]* P2.4  -&amp;gt; Bit[4]* P2.5  -&amp;gt; Bit[5]* P2.6  -&amp;gt; Bit[6] -&amp;gt; Output dir : 1
                        MOVT    R2, #0x0000             ;/* b0000_0000_0000_0000_0000_0000_0111_1100 */
                        STR     R2, [R3, #0]


loop

                        B       loop

                        END
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
The first part was copied from build-in startup file.&lt;br /&gt;
But it didn&amp;#39;t fix the problem....&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/142570?ContentTypeID=1</link><pubDate>Sat, 20 Feb 2010 03:37:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:653af9d1-bd51-4a2a-bd11-7b62c226bcd5</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
STR R2, [R3, #0] doesn&amp;#39;t work also. Fro me the problem is not the
instruction but one additional line in the code.&lt;br /&gt;
I copied the code from:&lt;br /&gt;

&lt;a href="http://embeddedfreak.wordpress.com/2009/08/09/cortex-m3-blinky-in-assembly/"&gt;embeddedfreak.wordpress.com/.../&lt;/a&gt;&lt;br /&gt;

It is the same board.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/139484?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 11:08:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6f17f9b6-26c5-4da8-92ec-e33f3b1830f5</guid><dc:creator>Tamir Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;must generate an access fault...&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
this is not true for all ARM processors. in fact, STR is
documented to have the ability to handle unaligned accesses on ARM7
and Cortex M3 !&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/136060?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 10:36:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:82c21301-8fcf-44be-ad97-0a1b3531fd4e</guid><dc:creator>Gp F</dc:creator><description>&lt;p&gt;&lt;p&gt;
Time to add a data-abort handler and reading about data alignments
- R3 contains an unaligned address so&lt;/p&gt;

&lt;pre&gt;
STR R2,[R3]
&lt;/pre&gt;

&lt;p&gt;
must generate an access fault...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/125990?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 08:29:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6724b779-bce7-4ed2-af28-db1aca847609</guid><dc:creator>Non Keil Related</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;There is no pure assembler project in Keil MDK.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Who suggested there was?&lt;/p&gt;

&lt;p&gt;
The startup code is in assembler - So there would be the starting
point.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/125997?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 06:16:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cb143ed5-af09-4b49-a643-a8332291eaf4</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
Another problem. I don&amp;#39;t know why the board executes only
specified number of instructions. Here is the example:&lt;/p&gt;

&lt;pre&gt;
STACK_TOP   EQU   0x10000200         ; constant for SP starting value
                        AREA  |Header Code|, CODE
            DCD    STACK_TOP  ; Stack top
            DCD    Start      ; Reset vector
            ENTRY             ; Indicate program execution start here
Start       ; Start of main program

                        MOV             R1, #10

                        MOVW    R3, #0xC040             ;P2.2, P2.3, P2.4, P2.5, and P2.6 function mode is located at FP2DIR (0&amp;Atilde;&amp;mdash;2009_C040).
                        MOVT    R3, #0x2009

                        MOVW    R2, #0x007C             ;P2.2  -&amp;gt; Bit[2] * P2.3  -&amp;gt; Bit[3]* P2.4  -&amp;gt; Bit[4]* P2.5  -&amp;gt; Bit[5]* P2.6  -&amp;gt; Bit[6] -&amp;gt; Output dir : 1
                        STR     R2, [R3]

loop

                        B       loop

END
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
This program executes correctly. It defines the GPIO ports as output.
On board leds are off (after reset state normally all leds are
on).&lt;br /&gt;
Then I modified the program by adding the same line&lt;/p&gt;

&lt;pre&gt;
STACK_TOP   EQU   0x10000200         ; constant for SP starting value
                        AREA  |Header Code|, CODE
            DCD    STACK_TOP  ; Stack top
            DCD    Start      ; Reset vector
            ENTRY             ; Indicate program execution start here
Start       ; Start of main program

                        MOV             R1, #10
&lt;b&gt;                     MOV             R1, #10&lt;/b&gt;

                        MOVW    R3, #0xC040             ;P2.2, P2.3, P2.4, P2.5, and P2.6 function mode is located at FP2DIR (0&amp;Atilde;&amp;mdash;2009_C040).
                        MOVT    R3, #0x2009

                        MOVW    R2, #0x007C             ;P2.2  -&amp;gt; Bit[2] * P2.3  -&amp;gt; Bit[3]* P2.4  -&amp;gt; Bit[4]* P2.5  -&amp;gt; Bit[5]* P2.6  -&amp;gt; Bit[6] -&amp;gt; Output dir : 1
                        STR     R2, [R3]

loop

                        B       loop

END
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
So normally the program does the same but now leds are still on so
the instruction STR R2, [R3] is not executing.&lt;br /&gt;
Where is the problem?&lt;br /&gt;
I&amp;#39;m using keil compilers as follows:&lt;/p&gt;

&lt;pre&gt;
&amp;quot;C:\Program Files\keil\ARM\BIN40\armasm&amp;quot; --device darmp1 -o .\blinky.o .\blinky.s
&amp;quot;C:\Program Files\keil\ARM\BIN40\armlink&amp;quot; --device darmp1 --rw_base 0x10000000 --ro_base 0x0 --map -o .\blinky.elf .\blinky.o
&amp;quot;C:\Program Files\keil\ARM\BIN40\fromelf&amp;quot; --bin --output .\blinky.bin .\blinky.elf
&amp;quot;C:\Program Files\keil\ARM\BIN40\fromelf&amp;quot; --i32 --output .\blinky.hex .\blinky.elf
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/115555?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 03:54:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:379fb92a-0bdf-4769-ade7-4072702232c5</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
There is no pure assembler project in Keil MDK.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/103774?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 03:31:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6836c1c2-6d2a-4217-81a7-699296a424ed</guid><dc:creator>Non Keil Related</dc:creator><description>&lt;p&gt;&lt;p&gt;
1 - Find an example program from Keil for your processor.&lt;br /&gt;
2 - Change the &amp;#39;main&amp;#39; function to a do nothing.&lt;br /&gt;
3 - Compile the project.&lt;br /&gt;
4 - Now examine, understand and learn from the startup.&lt;/p&gt;

&lt;p&gt;
Simple.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/78121?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2010 02:16:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f2c454d8-baeb-4a9c-a6ed-81c3f22da145</guid><dc:creator>Czarek Zegarek</dc:creator><description>&lt;p&gt;&lt;p&gt;
I compiled above program from command line and it is working. In
Keil i can&amp;#39;t compile it. It still needs Reset_Handler label even if I
changed Start to Reset_Handler.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asm programming</title><link>https://community.arm.com/thread/57756?ContentTypeID=1</link><pubDate>Thu, 18 Feb 2010 12:09:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8c38eed0-e239-4a2e-860e-ade22214692a</guid><dc:creator>Non Keil Related</dc:creator><description>&lt;p&gt;&lt;p&gt;
Why not study, experiment and learn to understand what&amp;#39;s happening
with the startup code. Leave the &amp;#39;main&amp;#39; in C to begin with and remove
it when you understand how to.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>