<?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>Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25515/calling-an-assembly-functon-from-c-rvmdk</link><description> 
Hello, 

 
I am struggling to do something that should be very simple: call
an assembly function from a C function. Can anyone give me some
pointers or an example of how to do this? 

 
I am using uVision 3 with Realview MDK C compiler. 

 
All of the</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/144691?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2009 09:12:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9c58a69a-1b15-4a9d-9ea7-c2224bc5d180</guid><dc:creator>Eric Severson</dc:creator><description>&lt;p&gt;&lt;p&gt;
Yes, actually. I am following an example provided in the
documentation for doing this. See LPC24xx user manual chapter 30,
section 10.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/142391?ContentTypeID=1</link><pubDate>Sun, 23 Aug 2009 10:16:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:23e41073-1994-4a2e-a464-e828165eefcb</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I am passing control to the IAP/ISP bootloader by executing
code at address 0x7FFFFFF1.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
And does it say anywhere in the documentation that this is
sufficient to start the bootloader? As opposed to, say, a genuine
reset of the microcontroller?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/142393?ContentTypeID=1</link><pubDate>Thu, 20 Aug 2009 09:54:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c5256ffb-2eca-41a9-9d5d-bab750f71cd7</guid><dc:creator>Tamir Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
I&amp;#39;m thinking about this. will let you know if I come up with
something.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/139275?ContentTypeID=1</link><pubDate>Thu, 20 Aug 2009 08:00:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:06790b34-362b-447d-80d8-3f244e3f3d08</guid><dc:creator>Eric Severson</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Tamir,&lt;/p&gt;

&lt;p&gt;
So for the delay here. We had some fires come up that I had to
help take care of.&lt;/p&gt;

&lt;p&gt;
Actually, I am talking about the IAP/ISP bootloader built into the
LPC2300/2400 chips (not a bootloader application). I am passing
control to the IAP/ISP bootloader by executing code at address
0x7FFFFFF1.&lt;/p&gt;

&lt;p&gt;
I have found that launching to this address from supervisor mode
is not enough to get the IAP/ISP to take charge of its stack pointer.
It will work fine for the first several blocks, but as soon as it
gets to a 32KB block, it fails while accepting flash data. However,
if I set my stack pointer to point to the top of the internal memory,
all is well.&lt;/p&gt;

&lt;p&gt;
-Eric&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/135881?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 23:04:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:14c1b915-ea71-40f4-b422-e05f89b2c97c</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Eric,&lt;/p&gt;

&lt;p&gt;
Are you sure you are using a good startup file?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/135880?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 22:52:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ef1d909f-d4b6-4894-8795-fd6c4205be16</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;The reason for this is that their boot loader does not appear
to reset the stack pointer&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
you don&amp;#39;t need to mess around with the stack to fix this. when
passing control from the bootloader to the application, change the
processor to SVC mode - or more specifically - make the &amp;#39;jump to
application&amp;#39; function a SWI function. that will allow the addresses
of the stacks to be set in the application&amp;#39;s startup file code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/125646?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 15:09:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fb88e3e4-145a-4c2e-a400-1b42265a8388</guid><dc:creator>Eric Severson</dc:creator><description>&lt;p&gt;&lt;p&gt;
No, I have not. Do you have some experience with this?&lt;/p&gt;

&lt;p&gt;
My only reason for believing this to be the case is that I have
noticed when my SP is around the mid point of the internal RAM upon
entering NXP&amp;#39;s bootloader, the micro controller will stop responding
at the first 32KB block it gets to.&lt;/p&gt;

&lt;p&gt;
-Eric&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/115154?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 14:54:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:554c0e05-06a8-46a0-ad82-431c93daeaae</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Have you asked &lt;b&gt;NXP&lt;/b&gt; about this?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/101908?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 14:34:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:96e8ad1f-b585-431f-97ce-6e0c47999c83</guid><dc:creator>Eric Severson</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks for the advice everyone.&lt;/p&gt;

&lt;p&gt;
I am trying to modify the stack pointer before invoking NXP&amp;#39;s
flash boot loader to flash my LPC2468. The reason for this is that
their boot loader does not appear to reset the stack pointer, and if
it is invoked when the stack pointer is not towards the top of the
memory map, it will end up over writing its own stack.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/89924?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 14:30:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:96205b60-98b9-4e12-b133-d4a297b2c5bb</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Write a C function with the correct prototype.&lt;/p&gt;

&lt;pre&gt;
void asm_adjust_sp(unsigned n) {
    // some dummy code that accesses the parameter n
    // and have a side effect, so the compiler doesn&amp;#39;t
    // throws away the code.
    my_dummy_global_variable = n;
}
&lt;/pre&gt;

&lt;p&gt;
Look at the assembler listing of the function. Cut the relevant
parts and place in an assembler file, and then add your specific
action code.&lt;/p&gt;

&lt;p&gt;
Then add a function prototype in a header file:&lt;/p&gt;

&lt;pre&gt;
void asm_adjust_sp(unsigned);
&lt;/pre&gt;

&lt;p&gt;
But as Tamir notes, modifying the stack pointer is not a simple
task. It is way more advanced than calling an assembler function from
C. With a moved stack pointer, return addresses and auto variables
from the current call tree will no longer be available, so you must
think twice about returning to previous calling functions.&lt;/p&gt;

&lt;p&gt;
Before starting on this task: Please specify why you think you
have to modify the stack pointer from running C code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/56629?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 10:50:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cd319c6b-d3f5-4420-af28-b7baa0d8b369</guid><dc:creator>Christoph Franck</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Can anyone give me some pointers or an example of how to do
this?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Try the RealView compiler manuals from the ARM website. The
Developer guide has a chapter about mixing C and assembly.&lt;/p&gt;

&lt;p&gt;

&lt;a href="http://infocenter.arm.com/help/topic/com.arm.doc.dui0203i/DUI0203I_rvct_developer_guide.pdf"&gt;infocenter.arm.com/.../DUI0203I_rvct_developer_guide.pdf&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calling an Assembly Functon From C (RVMDK)</title><link>https://community.arm.com/thread/56637?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2009 10:01:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0d375ab4-8b83-468e-8c9b-832748b4e082</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
first&lt;/p&gt;

&lt;pre&gt;
void __asm __swi(0) disable_interrupts(void) ;
void __asm __SWI_0                                (void)
{
        MRS             R1, SPSR

        ORR             R1, R1, #0xC0 // disable IRQ and FIQ

        MSR             SPSR_c, R1

        BX LR
}
&lt;/pre&gt;

&lt;p&gt;
and&lt;/p&gt;

&lt;pre&gt;
disable_interrupts() ;
&lt;/pre&gt;

&lt;p&gt;
but you probably can drop the swi directive all together. by the
way, changing the stack pointer to very dangerous, unless you are
writing a preemptive kernel...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>