<?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>how can I return a value within embedded assembler?</title><link>https://community.arm.com/developer/tools-software/tools/f/armds-forum/600/how-can-i-return-a-value-within-embedded-assembler</link><description> Note: This was originally posted on 8th May 2009 at http://forums.arm.com Hi, does anybody know how I can write an embedded ASM function that returns the actual PSR value? I prefered to go on like this: int getCpsr( void ) { &amp;#160; int currentCPSR; &amp;#160; MRS</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1451?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:98b8dd94-20b9-4eab-a87d-284f13727ed2</guid><dc:creator>guestposter guestposter</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Try embedded Assembler&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;__asm unsigned getCpsr( void )&lt;/span&gt;&lt;br /&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;#160; MRS R0, APSR&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;#160; BX&amp;#160; LR ; return&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;And call it as normal C function.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1450?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f590dfc7-f1df-4b3d-85d5-5dc0545a8915</guid><dc:creator>guestposter guestposter</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Which compiler are you using? In RVCT 4.0, you can refer to local variables as if they were registers (so called &amp;quot;virtual registers&amp;quot;) so you are pretty close already. The code would look like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;int currentCPSR;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;__asm { MRS currentCPSR, CPSR };&lt;/span&gt;&lt;br /&gt;&lt;span&gt;return currentCPSR;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1449?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:45550596-76bb-4c03-987d-9ec73a87c010</guid><dc:creator>Bhaveet Shah</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Thanks,&lt;br /&gt;&lt;br /&gt;but this is also ARM machine language instruction. I cannot use this inline assembler&lt;br /&gt;__asm&amp;quot;.....&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;In this context, AFAIK, it is not inline assembler.&amp;#160; This is just telling the compiler to treat _cpsr as the if it were the APSR register in Cortex-M3 and it will generate the appropriate instructions for you when you use the _cpsr variable.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1448?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7c786ac1-70bf-493b-89f0-29c8f8b31afc</guid><dc:creator>zart zurt</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Normally ARM and Thumb-2 instruction sets are the same except the binary form. And in the link I provided , it said that CPSR named register was supported for all processors. Sorry , it did not work that way...&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1447?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:56323995-71a4-409f-a3aa-32be310f5a89</guid><dc:creator>zart zurt</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Hi,&lt;br /&gt;&lt;br /&gt;does anybody know how I can write an embedded ASM function that returns the actual PSR value? I prefered to go on like this:&lt;br /&gt;&lt;br /&gt;int getCpsr( void )&lt;br /&gt;{&lt;br /&gt;&amp;#160; int currentCPSR;&lt;br /&gt;&amp;#160; MRS currentCPSR, CPSR&lt;br /&gt;&amp;#160; return currentCPSR;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;how can I return a value within embedded assembler?&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;[url=&amp;quot;&lt;/span&gt;&lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0098a/armccref_cjahjdbg.htm" target="_blank"&gt;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0098a/armccref_cjahjdbg.htm&lt;/a&gt;&lt;span&gt;&amp;quot;]&lt;/span&gt;&lt;a target="_blank"&gt;http://infocenter.arm.com/help/index.jsp?t...ef_cjahjdbg.htm[/url]&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;ui32 read_cpsr()&lt;/span&gt;&lt;br /&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt; register ui32 _cpsr __asm(&amp;quot;cpsr&amp;quot;);&lt;/span&gt;&lt;br /&gt;&lt;span&gt; // ...&lt;/span&gt;&lt;br /&gt;&lt;span&gt; return _cpsr;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I could not test this as I do not have a Cortex-M3 cpu...&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1445?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1d98b280-bb48-48f6-b6a7-8c0ce032ed6a</guid><dc:creator>Sebastian Gaertner</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;but this is also ARM machine language instruction. I cannot use this inline assembler&lt;/span&gt;&lt;br /&gt;&lt;span&gt;__asm&amp;quot;.....&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how can I return a value within embedded assembler?</title><link>https://community.arm.com/thread/1446?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 10:58:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:78927a6f-5fd3-4521-b528-39e32a4f0e64</guid><dc:creator>Sebastian Gaertner</dc:creator><description>&lt;div&gt;&lt;i&gt;Note: This was originally posted on 8th May 2009 at &lt;a href="http://forums.arm.com"&gt;http://forums.arm.com&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I cannot use inline assembler inside my function like this:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;__asm { MRS currentCPSR, CPSR };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;because I use a Cortex-M3 which only supports Thumb mode.&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>