<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: When to use RTS in in-line assembly code? in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130304#M1014</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Crasycat,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Thank you for your explanation.&amp;nbsp; On reflection, it&amp;nbsp;may even&amp;nbsp;be "dangerous" to do an in-line exit, without use of the pragmas, since&amp;nbsp;you would need to be aware what the compiler&amp;nbsp;would be pushing onto the stack prior to the in-line, to avoid a crash.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I presume that there would be no restriction on this type of function&amp;nbsp;being called either as a C function, or as a JSR within other inline code.&amp;nbsp; Is this correct?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Sep 2006 20:41:20 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2006-09-15T20:41:20Z</dc:date>
    <item>
      <title>HC08: When to use RTS in in-line assembly code?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130302#M1012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Hello all,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Consider that we have a C function that consists entirely of in-line assembly code, of the form -&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;void func1(void)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;&amp;nbsp; asm {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;&amp;nbsp; ; // Assembly code here&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: 'Courier New'; font-size: 2;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;The question then arises about the inclusion of a final RTS instruction, or not.&amp;nbsp; I have seen examples of both.&amp;nbsp; My best guess is that if the function is called from C there should not be&amp;nbsp;RTS.&amp;nbsp; But if the function is called by other in-line code (JSR func1), the final RTS should be included.&amp;nbsp; If this is the case, this would seem to make the&amp;nbsp;calling of the function within both C and in-line assembly mutually excusive.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Can anyone clarify the situation for me? &amp;nbsp;One example is in the start08.c file generated by CW.&amp;nbsp; The &lt;SPAN style="font-family: 'Courier New';"&gt;loadByte()&lt;/SPAN&gt; function does include RTS.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Another couple of questions also arise -&lt;/SPAN&gt;&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="font-size: 2;"&gt;Whether to use asm or _asm for a block of in-line code - what is the difference between the two forms?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 2;"&gt;What is the correct way to make a comment within in-line assembly code, since the semi-colon has different meanings for C and assembler?&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;Regards,&lt;BR /&gt;Mac&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-09-15&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;04:39 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Message Edited by CrasyCat on &lt;SPAN class="date_text"&gt;2007-04-13&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:16 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Sep 2006 13:37:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130302#M1012</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-09-15T13:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: When to use RTS in in-line assembly code?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130303#M1013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Just my 10 cents here.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When a function is implemented as an inline assembly function (contains only inline assembly instructions), you do not have to explicitly generate the RTS or whatever exit code is requested.&lt;/DIV&gt;&lt;DIV&gt;The compiler will care about that for you.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Only case where you may have to add exit code yourself is if for any reason you want to exit the function some other places.&lt;/DIV&gt;&lt;DIV&gt;Anyway in that case also I would recommend to use the standard function exit code and branch to a label at the end of the function.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Main advantage of letting the compiler manage function exit code is that compiler knows how the function is invoked and will adjust exit code accordingly.&lt;/DIV&gt;&lt;DIV&gt;Exit code may be different depending if function is invoked using a&amp;nbsp; JSR or directly inlined in the calling function.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Just let the compiler manage this all &lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;loadByte is preceded by the pragmas&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#pragma NO_ENTRY&lt;BR /&gt;#pragma NO_EXIT&lt;BR /&gt;#pragma NO_FRAME&lt;BR /&gt;These pragmas explicitly tells the compiler to generate no entry or exit code. In that particular case the programmer decided to keep whole control over function entry and exit code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I would not use that as a standard.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Around your other questions,&lt;/DIV&gt;&lt;DIV&gt;asm and _asm have identical behavior. Only difference I know is asm is not accepted if you build with option "Strict ANSI" (-Ansi) activated. _asm will be accepted in strict ANSI mode as well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Comment in inline assembler can be specified in either ANSI C, C++ or assembly syntax.&lt;/DIV&gt;&lt;DIV&gt;So&amp;nbsp;you can use:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; ; ...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; // ...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;...&amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;; and // are valid till the end of the line, whereas /* */ strictly enclosed the&amp;nbsp;text in comment. Anything after */ will not be considered as comment.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I hope that helps.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Sep 2006 19:21:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130303#M1013</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-09-15T19:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: When to use RTS in in-line assembly code?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130304#M1014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Crasycat,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Thank you for your explanation.&amp;nbsp; On reflection, it&amp;nbsp;may even&amp;nbsp;be "dangerous" to do an in-line exit, without use of the pragmas, since&amp;nbsp;you would need to be aware what the compiler&amp;nbsp;would be pushing onto the stack prior to the in-line, to avoid a crash.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I presume that there would be no restriction on this type of function&amp;nbsp;being called either as a C function, or as a JSR within other inline code.&amp;nbsp; Is this correct?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Sep 2006 20:41:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130304#M1014</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-09-15T20:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: When to use RTS in in-line assembly code?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130305#M1015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I dont see any problem here.&lt;BR /&gt;Note that you cannot call the before mentioned loadByte from C code as this function does expect a very specific stack layout (not C compatible), it is not really a void (*)(void) function. If you call your code from C, you have to implemen the exact C calling convention.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Sep 2006 06:45:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-When-to-use-RTS-in-in-line-assembly-code/m-p/130305#M1015</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-09-16T06:45:42Z</dc:date>
    </item>
  </channel>
</rss>

