<?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>CodeWarrior for MCUのトピックRe: Using Assember Macros in C</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199977#M7516</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Using the block syntax for __asm {} does not work as with this syntax instructions are line terminated, and that the output of&amp;nbsp; a single C macro is a single line. Check the compiler manuals high level inline assembly about this too. (this was btw the first trap I mentioned in the prev post)&lt;BR /&gt;And C's macro replacement is a simple text replacement utility, therefore it will generate the identical output as search and replace with a text editor.&lt;BR /&gt;I guess in your code snippet, you lost some line continuations ('\') at the line ends in the macro.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Mar 2008 22:27:06 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2008-03-07T22:27:06Z</dc:date>
    <item>
      <title>Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199970#M7509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;First of all excuse me if this is in the wrong section, I think I am OK though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am writing a C programme on the HCS12 but need to use some assembler in it. I am using the __asm{}.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The assembler I need to input is a bit repetitive, i.e using the same statements again. I understand macros can be used to reduce the code written.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Two questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can I use macros when I am embedding assembler in C and if so where can I put it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are there any extra clock cycles added on using macros instead of just writing the code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Colin&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2008 02:59:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199970#M7509</guid>
      <dc:creator>Deadstar</dc:creator>
      <dc:date>2008-03-06T02:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199971#M7510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Macros in C are just replacing text, so they can&amp;nbsp; be used for any kind of tasks in C.&lt;BR /&gt;With respect to HLI and macros there are two traps to look out for.&lt;BR /&gt;- macros expand to a single source code line, but the __asm{} syntax is using end of line for each instruction, so that does not mix. Instead with macros use the __asm nop; syntax:&lt;BR /&gt;#define ONE_NOP __asm nop;&lt;BR /&gt;&lt;BR /&gt;The second issue is with the # character, that one has a specific meaning to the preprocessor. If your HLI code contains #, then the C language meaning has to be disabled, there is a pragma for it. E.g.&lt;BR /&gt;&lt;BR /&gt;#pragma NO_STRING_CONSTR&lt;BR /&gt;#define LOAD_0 LDD #0&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2008 09:39:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199971#M7510</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-06T09:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199972#M7511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;That code isn't portable though. The # symbol is a perfect argument of why macros shouldn't be used for inline assembler. And there are loads of other issues with macros.&lt;BR /&gt;&lt;BR /&gt;My advise is to stay away from the pre-processor and write functions instead. That will also make the code way more readable. And if performance is critical, use inline functions. CW supports it even for "classic" C.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;#pragma INLINE
void one_nop (void)
{
  __asm NOP;
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2008 16:01:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199972#M7511</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-03-06T16:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199973#M7512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Well, if there are portability concerns, then those do rule out the use of inline assembly in the first placeI would assume.&lt;BR /&gt;So for simple tasks like adding a nop ( :smileywink: ) enabling interrupt I consider using HLI directly (or via macro) is fine. There are also cases where using inlined HLI functions generates more code or is not even possible, say when the HLI code has to access arguments, or when it includes control flow like branches or an direct error return.&lt;BR /&gt;Anyway, the question was how to use macros with assembly, I showed one way, using inline functions is another one.&lt;BR /&gt;A third one actually is to write the function with the assembler and not embedded in C with the inline assembler.&lt;BR /&gt;The assembler has its own macro's which work different from the C language ones as they do not just replace text but instead they are inserting instructions. Assembly macros also support conditional compilation internally, so for different arguments they can generate completely different output.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2008 23:02:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199973#M7512</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-06T23:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199974#M7513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hey guys,&lt;BR /&gt;&lt;BR /&gt;I got a bit lost looking at your posts. Perhaps if I explain more clearly I will make more sense.&lt;BR /&gt;&lt;BR /&gt;I am looking to replicate the following code 20X&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;LDAA 0,XSTAA PTT      LSL PTTLSL PTTLSL PTTLSL PTTLSL PTTLSL PTTLSL PTTINX&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;Now every clock cycles is very important, I really need to minimize them, so instead of just using copy/paste 20x I was hoping I could use some sort of a macro to make it easier to read.&lt;BR /&gt;&lt;BR /&gt;The assembler above is embedded within C code, hence I used __asm{} around it.&lt;BR /&gt;&lt;BR /&gt;Thanks again, I appreciate the effort,&lt;BR /&gt;&lt;BR /&gt;Colin&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 06:51:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199974#M7513</guid>
      <dc:creator>Deadstar</dc:creator>
      <dc:date>2008-03-07T06:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199975#M7514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello Colin,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You appear to be shifting a single bit from LSB to MSB position.&amp;nbsp; Firstly, there is a simpler and faster way to do this.&amp;nbsp; By rotating in the opposite direction, and using the accumulator for the rotate, you will save many cycles.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; LDAA&amp;nbsp; 0,X&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; RORA&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; RORA&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; ANDA&amp;nbsp; #$80&lt;BR /&gt;&amp;nbsp;&amp;nbsp; STAA&amp;nbsp; PTT&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; INX&lt;BR /&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;A macro might take the following form -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;&lt;FONT size="2"&gt;Code:&lt;/FONT&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;FONT size="2"&gt;#pragma NO_STRING_CONSTR#define shift_PTT  __asm ldaa 0,x; __asm rora; __asm rora; asm anda #$80; __asm staa PTT; __asm inx;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;Not a pretty sight!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-03-07&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:13 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 09:05:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199975#M7514</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-07T09:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199976#M7515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The reason I used all the shifts is I am looking to output all the bits in PTT in order as quickly as possible - i.e. looking at PTT-bit7.&lt;BR /&gt;&lt;BR /&gt;Why do you use __asm for every line? Could I not just enclose all the assembler in one __asm{} as below?&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#pragma NO_STRING_CONSTR#define shift_PTT  __asm{LDAA 0,XSTAA PTT  LSL PTTLSL PTTLSL PTTLSL PTTLSL PTTLSL PTTLSL PTTINX };&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;Also if I use this method would it add any additional clock cycels, or does the compiler litterally replace all shift_PTTs by this code?&lt;BR /&gt;&lt;BR /&gt;Colin&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 19:26:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199976#M7515</guid>
      <dc:creator>Deadstar</dc:creator>
      <dc:date>2008-03-07T19:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using Assember Macros in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199977#M7516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Using the block syntax for __asm {} does not work as with this syntax instructions are line terminated, and that the output of&amp;nbsp; a single C macro is a single line. Check the compiler manuals high level inline assembly about this too. (this was btw the first trap I mentioned in the prev post)&lt;BR /&gt;And C's macro replacement is a simple text replacement utility, therefore it will generate the identical output as search and replace with a text editor.&lt;BR /&gt;I guess in your code snippet, you lost some line continuations ('\') at the line ends in the macro.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 22:27:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-Assember-Macros-in-C/m-p/199977#M7516</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-07T22:27:06Z</dc:date>
    </item>
  </channel>
</rss>

