<?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: How to? Indexed addressing of 16-bit values. in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201466#M16505</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, you're not using a 9S08.&amp;nbsp; Then, some more work is needed.&amp;nbsp; Right off the top of my head, one (untested/unoptimized) possibility is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    lda       POSITION_ON_LIST    ;stack a word with value                    lsla                          ;(multiplied by two)                    psha                    clra                    rola                    psha                    lda       2,sp                ;now, add table address                    add       #[WordTable                    sta       2,sp                    pula                    adc       #]WordTable                    psha                    pulhx                         ;HX -&amp;gt; table entry                    lda       1,x                 ;now, load HX with word value                    psha                    lda       ,x                    psha                    pulhx&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Notes: ASM8-based example. So, macro PULHX is PULH followed by PULX, [ gets lower part of word, while ] get higher part of word. One possible optimization (one byte, same cycles) would be a TSX before the lda 2,sp and then lda 1,x ... sta 1,x&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Apr 2011 18:00:05 GMT</pubDate>
    <dc:creator>tonyp</dc:creator>
    <dc:date>2011-04-28T18:00:05Z</dc:date>
    <item>
      <title>How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201462#M16501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What I want to know is probably easy-peasy once you already know how...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to read a value of 0-255 from the outside world and depending on this value, look down a list of 255 16-bit values and select a corresponding value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Down the bottom somewhere I suppose I would have a list:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ORG $whatever&lt;/P&gt;&lt;P&gt;FDB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #12345&lt;/P&gt;&lt;P&gt;FDB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #65535&lt;/P&gt;&lt;P&gt;FDB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #35&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and to read one of these values I would have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LDX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; POSITION_ON_LIST (outside-world value)&lt;/P&gt;&lt;P&gt;LDHX&amp;nbsp;&amp;nbsp;&amp;nbsp; $whatever,X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then hopefully HX gets loaded with the value on the list corresponding to the value that was placed in X. Seeing that my list of values are 16 bit they take up pairs of memory locations, so does X really know to point to only every even value address, not even and odd like if it were addressing a list of 8 bit values?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Apr 2011 20:07:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201462#M16501</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2011-04-27T20:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201463#M16502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No automatic way, you first need to shift the value to the left once to multiply&lt;BR /&gt;it by two, and then use the offset.&amp;nbsp; You need something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    clrh                    ldx       POSITION_ON_LIST                    lslx                    bcc       LookUp                    pshh                    inc       1,sp                    pulhLookUp              ldhx      WordTable,x&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Apr 2011 20:27:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201463#M16502</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2011-04-27T20:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201464#M16503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;or in the same vein.... but maybe faster ?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;clra&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;ldx POSITION_ON_LIST&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;lslx&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;rola&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;psha&lt;/P&gt;&lt;P&gt;&lt;SPAN style="white-space: pre;"&gt;&lt;/SPAN&gt;pulh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ldhx WordTable,x&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 03:34:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201464#M16503</guid>
      <dc:creator>donw</dc:creator>
      <dc:date>2011-04-28T03:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201465#M16504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay - starting to look good.&lt;/P&gt;&lt;P&gt;But if I want to LDHX I can only do it in direct mode, i.e. from $00 to $FF.&lt;/P&gt;&lt;P&gt;Flash memory starts WAY above this and that is where the Wordtable would be.&lt;/P&gt;&lt;P&gt;There is not enough RAM to copy it all to there. What now?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 17:21:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201465#M16504</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2011-04-28T17:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201466#M16505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, you're not using a 9S08.&amp;nbsp; Then, some more work is needed.&amp;nbsp; Right off the top of my head, one (untested/unoptimized) possibility is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    lda       POSITION_ON_LIST    ;stack a word with value                    lsla                          ;(multiplied by two)                    psha                    clra                    rola                    psha                    lda       2,sp                ;now, add table address                    add       #[WordTable                    sta       2,sp                    pula                    adc       #]WordTable                    psha                    pulhx                         ;HX -&amp;gt; table entry                    lda       1,x                 ;now, load HX with word value                    psha                    lda       ,x                    psha                    pulhx&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Notes: ASM8-based example. So, macro PULHX is PULH followed by PULX, [ gets lower part of word, while ] get higher part of word. One possible optimization (one byte, same cycles) would be a TSX before the lda 2,sp and then lda 1,x ... sta 1,x&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 18:00:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201466#M16505</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2011-04-28T18:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201467#M16506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;On second look, the only instruction that causes problems is the LDHX WordTable,x&lt;/P&gt;&lt;P&gt;So, keep it the same as the first and change only the LookUp section to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LookUp              lda       WordTable+1,x                    psha                    lda       WordTable,x                    psha                    pulhx&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 19:47:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201467#M16506</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2011-04-28T19:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201468#M16507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you have it, tonyp. I'll give that a try. It's 11:26 pm here and the brain is getting more foggy than usual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the meantime I was thinking of spltting the words into two separate lists of MS and LS bytes and then doing something like this, but your approach seems MUCH better. Splitting the words is messy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  LDA LS_BYTE_TABLE,POSITION_ON_LIST  PSHA  LDA MS_BYTE_TABLE,POSITION_ON_LIST    PSHA  PULH  PULX&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 20:26:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201468#M16507</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2011-04-28T20:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201469#M16508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LookUp              lda       WordTable+1,x&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;would have an offset of up to 511 so X by itself would not cut it. Only HX would and I can't use it &lt;IMG alt="Smiley Sad" class="emoticon emoticon-smileysad" id="smileysad" src="https://community.nxp.com/i/smilies/16x16_smiley-sad.png" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 12:55:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201469#M16508</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2020-11-02T12:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201470#M16509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The LDA supports 16-bit offset for X index even with the HC08, so I don't see the problem.&amp;nbsp; From the CPU08 reference:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG border="0" src="http://www.aspisys.com/lda.jpg" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 20:49:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201470#M16509</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2011-04-28T20:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201471#M16510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tonyp, you are dead right. I just now ran it on some hardware and it was perfect. &lt;IMG alt=":smileytongue:" class="emoticon emoticon-smileytongue" id="smileytongue" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-tongue.gif" title="Smiley Tongue" /&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for all your help. 12:17 pm - time to go to bed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 21:18:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201471#M16510</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2011-04-28T21:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201472#M16511</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;I am not sure what the perceived problem is about?&amp;nbsp; The LDHX instruction for the 9S08 has a 16-bit offset version.&amp;nbsp; So the original expression should be quite&amp;nbsp;OK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LDHX&amp;nbsp; WordTable,X&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&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,courier"&gt;&lt;/FONT&gt;&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>Fri, 29 Apr 2011 12:04:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201472#M16511</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-04-29T12:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201473#M16512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem was he&amp;nbsp; is using a HC08 (not a 9S08) and certain addressing modes many of us (who have completely abandoned the HC08) take for granted are missing, including the indexed LDHX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 14:22:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201473#M16512</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2011-04-29T14:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201474#M16513</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;This sort of confusion can easily be avoided if the derivative used is mentioned within the OP.&amp;nbsp; I admit that my psychic powers are somewhat limited in the mind reading department.&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>Fri, 29 Apr 2011 14:49:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201474#M16513</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-04-29T14:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to? Indexed addressing of 16-bit values.</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201475#M16514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Until now I thought that anything ending in "08" had identical instructions, just that some had extra ones. LDHX I thought was uniform across the range.&lt;/P&gt;&lt;P&gt;I'm predominantly a hardware engineer, that's the problem :smileywink:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Apr 2011 13:17:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-Indexed-addressing-of-16-bit-values/m-p/201475#M16514</guid>
      <dc:creator>JimDandy</dc:creator>
      <dc:date>2011-04-30T13:17:43Z</dc:date>
    </item>
  </channel>
</rss>

