<?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中的主题 Re: How to mirror a byte</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158162#M4856</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;If my estimations are correct, the byte table lookup method should occupy about 7 cycles.&amp;nbsp; The nybble table lookup method would seem much less efficient at about 30 cycles (using assembly code, rather than C).&amp;nbsp; This would compare with the "shift loop" method at about 44 cycles.&amp;nbsp; I assumed that ACCB contained the byte value to be mirrored, and that the result was also in ACCB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The byte table lookup code might consist of the following:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ldx&amp;nbsp;&amp;nbsp; #BYTETAB&amp;nbsp;&amp;nbsp; ; Start of byte table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; abx&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ldab&amp;nbsp; 0,x&lt;/FONT&gt;&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>Thu, 03 Dec 2009 04:53:45 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2009-12-03T04:53:45Z</dc:date>
    <item>
      <title>How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158158#M4852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi to all,&lt;/P&gt;&lt;P&gt;i would like to say if in the HCS12 assembler there is a instruction to mirror a byte.&lt;/P&gt;&lt;P&gt;That is, "convert" a byte in his mirror, for example:&lt;BR /&gt;$01 --&amp;gt; $80&lt;/P&gt;&lt;P&gt;$A1 --&amp;gt; $85&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An istruction o a set of instruction (the fatest) .&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Nov 2009 18:12:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158158#M4852</guid>
      <dc:creator>pelle2005reg</dc:creator>
      <dc:date>2009-11-30T18:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158159#M4853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The fastest way is probably a table lookup if you can afford the memory for a 256 bytes table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Dec 2009 14:24:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158159#M4853</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-12-01T14:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158160#M4854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;This C code is fairly effective too. It works on nibble-level instead of byte-level, to save ROM:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;#pragma CONST_SEG GLOBAL_ROM

static const uint8 MIRROR_TABLE[16] =
{
  0x0, 0x8, 0x4, 0xC,  /*  0-3  */
  0x2, 0xA, 0x6, 0xE,  /*  4-7  */
  0x1, 0x9, 0x5, 0xD,  /*  8-11 */
  0x3, 0xB, 0x7, 0xF   /* 12-15 */
};

#pragma CONST_SEG DEFAULT


uint8 my_byte; /* byte to mirror */
uint8 tmp;

tmp = MIRROR_TABLE[my_byte &amp;gt;&amp;gt; 4];
tmp &amp;lt;&amp;lt;= 4;
my_byte = MIRROR_TABLE[my_byte &amp;amp; 0x0F] | tmp;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;On a Freescale micro, the left shift will be optimized into a MUL instruction, saving a few ticks. The right shift will become 4 LSRx instructions (no optimization possible).&lt;BR /&gt;&lt;BR /&gt;If you expand the lookup table from 16 bytes to 256 bytes you don't need to do the shifting and thus save 10 CPU ticks or so, at the cost of ROM.&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;&lt;/SPAN&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Lundin on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-12-01&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:46 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:03:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158160#M4854</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2020-10-29T09:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158161#M4855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The table solution was also my first idea.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2009 00:07:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158161#M4855</guid>
      <dc:creator>pelle2005reg</dc:creator>
      <dc:date>2009-12-03T00:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158162#M4856</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;If my estimations are correct, the byte table lookup method should occupy about 7 cycles.&amp;nbsp; The nybble table lookup method would seem much less efficient at about 30 cycles (using assembly code, rather than C).&amp;nbsp; This would compare with the "shift loop" method at about 44 cycles.&amp;nbsp; I assumed that ACCB contained the byte value to be mirrored, and that the result was also in ACCB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The byte table lookup code might consist of the following:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ldx&amp;nbsp;&amp;nbsp; #BYTETAB&amp;nbsp;&amp;nbsp; ; Start of byte table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; abx&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ldab&amp;nbsp; 0,x&lt;/FONT&gt;&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>Thu, 03 Dec 2009 04:53:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158162#M4856</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-12-03T04:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158163#M4857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HC12 indexed addressing allows LDAB&amp;nbsp; B,X&amp;nbsp; , so -2 cycles saved on ABX.&lt;/P&gt;&lt;P&gt;Also loop unrolling should be considered. With single cycle shift instructions RORB, ROLA, or similar, reversing&amp;nbsp;bits order from&amp;nbsp;B to&amp;nbsp;A should take 2cycles per bit, 2*8=16 cycles. + 1 cycle to transfer result back from A to B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2009 17:52:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158163#M4857</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-12-03T17:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to mirror a byte</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158164#M4858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The C code to mirror a byte may be fairly effective, but unfortunately it&amp;nbsp;doesn't work.&lt;/P&gt;&lt;P&gt;It basically does what it should but swaps the output nibbles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this&amp;nbsp;&amp;nbsp;instead:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;tmp = MIRROR_TABLE[my_byte &amp;amp; 0x0F];&lt;BR /&gt;tmp &amp;lt;&amp;lt;= 4;&lt;BR /&gt;my_byte = MIRROR_TABLE[my_byte &amp;gt;&amp;gt; 4]; | tmp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Anders Johansson&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 May 2010 19:18:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-mirror-a-byte/m-p/158164#M4858</guid>
      <dc:creator>AndersJ</dc:creator>
      <dc:date>2010-05-17T19:18:46Z</dc:date>
    </item>
  </channel>
</rss>

