<?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 inline assembler instructions with offsets in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169534#M5137</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;this seemingly simple inline instruction won't compile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
char c;char d;void foobar(void){&amp;nbsp; __asm&amp;nbsp;&amp;nbsp; movb c , d : 1 ; // access byte behind d}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It generates an error C12089: ',' expected before next element&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version with '+' or reversed order yield the same result. It seems that the assembler can't generate the necessary offset calculation to produce the desired access.&amp;nbsp; The reason I want to have this is a C array which I want to access with indices which carry an offset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#define OFS -4char x[8];char get(char c) // c ranges from 4 .. 11{&amp;nbsp;&amp;nbsp;&amp;nbsp; return x[OFS + c];}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course on can always do the offset calculation at runtime, at the cost of extra bytes and cycles:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#define OFS -4char x[8];char get(char c) // c ranges from 4 .. 11{&amp;nbsp;&amp;nbsp;&amp;nbsp; c += OFS;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x[c];}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;P&gt;But this negates the whole purpose of using inline assembly IMO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a solution to this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:17:34 GMT</pubDate>
    <dc:creator>slarti</dc:creator>
    <dc:date>2020-10-29T09:17:34Z</dc:date>
    <item>
      <title>inline assembler instructions with offsets</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169534#M5137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;this seemingly simple inline instruction won't compile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
char c;char d;void foobar(void){&amp;nbsp; __asm&amp;nbsp;&amp;nbsp; movb c , d : 1 ; // access byte behind d}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It generates an error C12089: ',' expected before next element&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version with '+' or reversed order yield the same result. It seems that the assembler can't generate the necessary offset calculation to produce the desired access.&amp;nbsp; The reason I want to have this is a C array which I want to access with indices which carry an offset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#define OFS -4char x[8];char get(char c) // c ranges from 4 .. 11{&amp;nbsp;&amp;nbsp;&amp;nbsp; return x[OFS + c];}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course on can always do the offset calculation at runtime, at the cost of extra bytes and cycles:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#define OFS -4char x[8];char get(char c) // c ranges from 4 .. 11{&amp;nbsp;&amp;nbsp;&amp;nbsp; c += OFS;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x[c];}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;P&gt;But this negates the whole purpose of using inline assembly IMO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a solution to this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:17:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169534#M5137</guid>
      <dc:creator>slarti</dc:creator>
      <dc:date>2020-10-29T09:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: inline assembler instructions with offsets</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169535#M5138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please don't forget to mention target name at least. Codewarrior version also would be nice know. I guess we are talking about CW for HC12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems inline assembler treats "d" variable as d register. If you rename d to something else, for example dd, your code starts compiling and emits warning C10030 Offset out of Object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jan 2010 17:24:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169535#M5138</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2010-01-22T17:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: inline assembler instructions with offsets</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169536#M5139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;kef wrote:&lt;BR /&gt;&lt;P&gt;Please don't forget to mention target name at least. Codewarrior version also would be nice know. I guess we are talking about CW for HC12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems inline assembler treats "d" variable as d register. If you rename d to something else, for example dd, your code starts compiling and emits warning C10030 Offset out of Object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ouch! Completely missed the D register name clash. The problem stays somewhat the same, at least&amp;nbsp;for positive offsets. Funny enough, with negative offsets the&amp;nbsp; code compiles ok. All in all, the inline assembler seems to be severely restricted for no good reason anyway:&lt;/P&gt;&lt;PRE&gt;
struct foo{  char c;  long ignore;  char c2;};struct foo bar;void foobar(void){  __asm addb #bar.c2 - bar.c;  __asm addb #(bar.c2 - bar.c);  __asm addb @bar.c2 - @bar.c;  __asm addb (@bar.c2 - @bar.c);  __asm addb #(@bar.c2 - @bar.c);}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of the above statements compiles ok. Is there a way to move around in a struct via offset arithmetic (at compile time)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: the target is an S12X and the suite is a CW 4.6 - OTOH I suppose the problems will not be confined to one certain version as it doesn't look like a bug but rather a restriction.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:17:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169536#M5139</guid>
      <dc:creator>slarti</dc:creator>
      <dc:date>2020-10-29T09:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: inline assembler instructions with offsets</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169537#M5140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One way to code this is to compute the size as an enum with the ANSI offsetof in C code and then in the hli code to read the enum.&lt;/P&gt;&lt;P&gt;This way all the C operations and syntax can be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#include &amp;lt;stddef.h&amp;gt;struct A { int field1; int field2;};enum { offset_field1 = offsetof(struct A, field1), offset_field2 = offsetof(struct A, field2)};void fun(void){ __asm LDD  #offset_field2 - offset_field1; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&amp;nbsp;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:17:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/inline-assembler-instructions-with-offsets/m-p/169537#M5140</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T09:17:37Z</dc:date>
    </item>
  </channel>
</rss>

