<?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>S12 / MagniV Microcontrollers中的主题 Need to word align tables in code space</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177015#M6242</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;system: Codewarrior 4.6&lt;/DIV&gt;&lt;DIV&gt;processor: 9s12c32&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This will actually be a two part question.&amp;nbsp; First, what is the correct way to define a table in code.&amp;nbsp; I have it defined as:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const unsigned int Table1[8] = {0,1,2,3,4,5,6,7};&lt;/DIV&gt;&lt;DIV&gt;The compiler will place it in flash or ROM depending upon how I use the table in the program.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For example:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; unsigned int i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1[0]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;Places the table at address 0 in RAM but, ....&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; const unsigned int * i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1;&lt;/DIV&gt;&amp;nbsp;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;Places the table at address 0xC043.&amp;nbsp; Is there a better way to define the table such that it will always wind up in code space?&amp;nbsp; I tried using #pragma CODE_SEG but the compiler just ignored it.&amp;nbsp; Any help is appreciated.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Second question:&amp;nbsp; What compiler directive or technique can be used to word align the table?&lt;/DIV&gt;&lt;DIV&gt;The align directive (#pragma align 2) doesn't work.&amp;nbsp;&amp;nbsp; Doing a test compile then poking a byte in if needed is not an option.&amp;nbsp;&amp;nbsp; Fixing the table at a defined address is not an option either, although I would like to know how to do that.&amp;nbsp; Basically the table should be relocatable, always the same size and always begin on an even word.&amp;nbsp; Thanks, hope you can help.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Jan 2008 07:04:39 GMT</pubDate>
    <dc:creator>Nickx</dc:creator>
    <dc:date>2008-01-04T07:04:39Z</dc:date>
    <item>
      <title>Need to word align tables in code space</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177015#M6242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;system: Codewarrior 4.6&lt;/DIV&gt;&lt;DIV&gt;processor: 9s12c32&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This will actually be a two part question.&amp;nbsp; First, what is the correct way to define a table in code.&amp;nbsp; I have it defined as:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const unsigned int Table1[8] = {0,1,2,3,4,5,6,7};&lt;/DIV&gt;&lt;DIV&gt;The compiler will place it in flash or ROM depending upon how I use the table in the program.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For example:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; unsigned int i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1[0]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;Places the table at address 0 in RAM but, ....&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; const unsigned int * i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1;&lt;/DIV&gt;&amp;nbsp;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;Places the table at address 0xC043.&amp;nbsp; Is there a better way to define the table such that it will always wind up in code space?&amp;nbsp; I tried using #pragma CODE_SEG but the compiler just ignored it.&amp;nbsp; Any help is appreciated.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Second question:&amp;nbsp; What compiler directive or technique can be used to word align the table?&lt;/DIV&gt;&lt;DIV&gt;The align directive (#pragma align 2) doesn't work.&amp;nbsp;&amp;nbsp; Doing a test compile then poking a byte in if needed is not an option.&amp;nbsp;&amp;nbsp; Fixing the table at a defined address is not an option either, although I would like to know how to do that.&amp;nbsp; Basically the table should be relocatable, always the same size and always begin on an even word.&amp;nbsp; Thanks, hope you can help.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2008 07:04:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177015#M6242</guid>
      <dc:creator>Nickx</dc:creator>
      <dc:date>2008-01-04T07:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need to word align tables in code space</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177016#M6243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; unsigned int i;&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1[0]&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;Places the table at address 0 in RAM but, ....&lt;BR /&gt;&lt;BR /&gt;No, the compiler directly assigns the value of Table1[0] to i,&lt;BR /&gt;or if i is not used afterwards, he wont even do that.&lt;BR /&gt;So Table1 is not at 0, its not linked. And address 0 is usually not RAM too, bye the way.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; void SomeFunction()&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp; {&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; const unsigned int * i;&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; i=Table1;&lt;/DIV&gt;&amp;gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;gt;Places the table at address 0xC043.&amp;nbsp;&lt;BR /&gt;&amp;gt;Is there a better way to define the table such that it will always &amp;gt;wind up in code space?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It does end up in the flash, if it ends up in the application. If you do not want that the compiler does constant propagation, make it volatile, but usually there is no need to do that.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I tried using #pragma CODE_SEG but the compiler just &amp;gt;ignored it.&amp;nbsp; Any help is appreciated.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;For&amp;nbsp; constants, the #pragma CONST_SEG&lt;/DIV&gt;&lt;DIV&gt;applies, check the compiler manual.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Second question:&amp;nbsp; What compiler directive or technique can&lt;BR /&gt;&amp;gt;be used to word align the table?&lt;/DIV&gt;&lt;DIV&gt;&amp;gt;The align directive (#pragma align 2) doesn't work.&amp;nbsp;&amp;nbsp; Doing a &amp;gt;test compile then poking a byte in if needed is not an option.&amp;nbsp;&amp;nbsp; &amp;gt;Fixing the table at a defined address is not an option either, &amp;gt;although I would like to know how to do that.&amp;nbsp; Basically the &amp;gt;table should be relocatable, always the same size and always &amp;gt;begin on an even word.&amp;nbsp; Thanks, hope you can help.&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;The alignment can be done in the *.prm file.&lt;BR /&gt;Use a #pragma CONST_SEG XXX and then place XXX into a placement defined with ALIGN 2, check the linker manual for details (or create a dummy project for the XGATE with the wizard for a S12X, the XGATE needs all its data 2 byte aligned too.)&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2008 08:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177016#M6243</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-01-04T08:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need to word align tables in code space</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177017#M6244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Here is another hint - you don't have to write code to figure out where things were placed, just examine the map file. It's your friend.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2008 11:43:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Need-to-word-align-tables-in-code-space/m-p/177017#M6244</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-01-04T11:43:54Z</dc:date>
    </item>
  </channel>
</rss>

