<?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: Accessing assembler-defined data in C as an array in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159830#M4337</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the ASM file, I assume that you have the label &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo:&lt;/FONT&gt; followed by a sequence of &lt;FONT color="#0000ff" face="courier new,courier"&gt;DC.W&lt;/FONT&gt; directives, and the comma separated table data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you export the &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo&lt;/FONT&gt; label using the &lt;FONT color="#0000ff" face="courier new,courier"&gt;XDEF Fo&lt;/FONT&gt;&amp;nbsp;directive, at the top of the ASM file?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the C file (or within an associated&amp;nbsp;header file) you would also&amp;nbsp;need to declare:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="courier new,courier"&gt;extern short Fo[];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;This should make the table data visible from the C file.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Aug 2011 23:04:27 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2011-08-16T23:04:27Z</dc:date>
    <item>
      <title>Accessing assembler-defined data in C as an array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159829#M4336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've upgraded my code for the quadrotor quite a bit, but it appears I need to expand the output range of the singeltons to beyond the unsigned char limit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a bit of a bear, however, because I don't know how to go from 8-bit unsigned chars to 16-bit signed shorts with this equation in assembler:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sum( S[ i ] * Fo[ i ] ) / sum( Fo[ i ] );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since my project is&amp;nbsp;mixed language, I decided to port this equation over to C. The equation works just fine, but now I'm having data access errors for Fo[ i ].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question boils down to this:&lt;/P&gt;&lt;P&gt;What's the best way to access a data list defined in .asm with the C language?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that I cannot port Fo[ i ], the data definied in the .asm, to C so easily... I'd pretty much have to convert the whole .asm into a .c function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2011 22:24:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159829#M4336</guid>
      <dc:creator>AirDragon</dc:creator>
      <dc:date>2011-08-16T22:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing assembler-defined data in C as an array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159830#M4337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the ASM file, I assume that you have the label &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo:&lt;/FONT&gt; followed by a sequence of &lt;FONT color="#0000ff" face="courier new,courier"&gt;DC.W&lt;/FONT&gt; directives, and the comma separated table data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you export the &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo&lt;/FONT&gt; label using the &lt;FONT color="#0000ff" face="courier new,courier"&gt;XDEF Fo&lt;/FONT&gt;&amp;nbsp;directive, at the top of the ASM file?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the C file (or within an associated&amp;nbsp;header file) you would also&amp;nbsp;need to declare:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="courier new,courier"&gt;extern short Fo[];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;This should make the table data visible from the C file.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080" face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2011 23:04:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159830#M4337</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-08-16T23:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing assembler-defined data in C as an array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159831#M4338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did just as you said with the &lt;FONT color="#0000ff" face="courier new,courier"&gt;XDEF&lt;/FONT&gt; and &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo:&lt;/FONT&gt; declarations, but with &lt;FONT color="#0000ff" face="courier new,courier"&gt;DS.B&lt;/FONT&gt; directives instead of &lt;FONT color="#0000ff" face="courier new,courier"&gt;DC.W&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The C file... well, I tried to use a pointer and have it point to the beginning address of the Fo array, but that didn't work out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going to try the &lt;FONT color="#0000ff" face="courier new,courier"&gt;extern char Fo[]&lt;/FONT&gt; and will see if that will work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2011 23:56:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159831#M4338</guid>
      <dc:creator>AirDragon</dc:creator>
      <dc:date>2011-08-16T23:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing assembler-defined data in C as an array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159832#M4339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello AD,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was under the impression that you needed to change the data&amp;nbsp;type from unsigned 8-bit, to signed 16-bit, or did I misunderstand?&amp;nbsp; If the table contains constant data, and is located in flash memory, the directive DC.W or DC.B is appropriate.&amp;nbsp; The data would be programmed at the same time that the code is programmed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The use of the DS.B (or DS.W) directive would indicate that the table data&amp;nbsp;is RAM based.&amp;nbsp; For example,&amp;nbsp; &lt;FONT face="courier new,courier"&gt;DS.B&amp;nbsp;100&lt;/FONT&gt; would define a memory block of 100 bytes that is not initialised - which would be done by your assembly code.&amp;nbsp; What is the actual scenario?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the C standpoint, an array name used alone represents the address of the first array element, which can then be assigned to a pointer of the appropriate type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;extern char Fo[];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;char *p;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;p = Fo;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Aug 2011 00:52:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159832#M4339</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-08-17T00:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing assembler-defined data in C as an array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159833#M4340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sorry for the confusion, but the &lt;FONT color="#0000ff" face="courier new,courier"&gt;S[]&lt;/FONT&gt; table is in ROM, and the &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo[]&lt;/FONT&gt; table&amp;nbsp;is in RAM (or at least it should be).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The assembler function I was working on made use of the HCS12's fuzzy logic instructions,&amp;nbsp;&lt;FONT color="#0000ff" face="courier new,courier"&gt;MEM&lt;/FONT&gt;, &lt;FONT color="#0000ff" face="courier new,courier"&gt;REV&lt;/FONT&gt;, and &lt;FONT color="#0000ff" face="courier new,courier"&gt;WAV&lt;/FONT&gt;. These instructions are 8-bit only, and will not work for 16-bit systems. So, in order to get a 16 or higher bit fuzzy logic function, you'd have to program it yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since the application is time critical (quad rotor balancing), I did not want to do too much programming in C as far as the controller subroutine goes... plus I didn't really feel like trying to make C versions of the &lt;FONT color="#0000ff" face="courier new,courier"&gt;MEM&lt;/FONT&gt;, &lt;FONT color="#0000ff" face="courier new,courier"&gt;REV&lt;/FONT&gt;, and &lt;FONT color="#0000ff" face="courier new,courier"&gt;WAV&lt;/FONT&gt; instructions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After some initial testing, I had concluded that the 8-bit range of the defuzzification phase wouldn't suffice. So I want to try using the same 8-bit data&amp;nbsp;(the &lt;FONT color="#0000ff" face="courier new,courier"&gt;Fo[]&lt;/FONT&gt; table) with a larger, 16-bit, &lt;FONT color="#0000ff" face="courier new,courier"&gt;S[]&lt;/FONT&gt; table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I was having earlier was that I didn't know how to use a pointer in C, nor did I know how to declare an array that's been externally declared in C... if that's how its said?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The good news is that I tried what you suggested, and it appears to be working, I'll have to do more tests now to see what else might be going on with it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Aug 2011 03:11:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Accessing-assembler-defined-data-in-C-as-an-array/m-p/159833#M4340</guid>
      <dc:creator>AirDragon</dc:creator>
      <dc:date>2011-08-17T03:11:22Z</dc:date>
    </item>
  </channel>
</rss>

