<?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>CodeWarrior for MCUのトピックRe: Effecient assembly code to add to the timer channel registers</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140031#M2388</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello again, FC:&lt;BR /&gt;&lt;BR /&gt;If you can finesse your timer so that the offset can fit in one byte, you could use the HC08s anemic 16-bit add, which can do it in 10 cycles. The offset would have to be either 0 through 127, or FFFF through FF00 (represented as -1 through -128).&lt;BR /&gt;&lt;BR /&gt;Remember to push/pull the H register if you use this, which will add 4 more cycles if you are not already doing a PSHH and PULH.&lt;PRE&gt;
;
; Add the ICR value to a SMALL constant offset and store in the OCR.
;
      ldhx    TPMC1V            ;  4  Get the ICR value
      aix     #time_base        ;  2  Add a small offset to it
      sthx    TPMC0V            ;  4  And store in the OCR
;                                =10 cycles
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 08:40:13 GMT</pubDate>
    <dc:creator>rocco</dc:creator>
    <dc:date>2020-10-29T08:40:13Z</dc:date>
    <item>
      <title>Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140028#M2385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Most of my programs are in C and I cannot determine the best way to code in assembly the following statement:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#define time_base 0xF424;&lt;/DIV&gt;&lt;DIV&gt;.&lt;/DIV&gt;&lt;DIV&gt;.&lt;/DIV&gt;&lt;DIV&gt;.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TPMC0V = TPMC1V + time_base; // Add input capture time + delay to TPMC0V&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I became lazy and relied on the compiler to generate the assemby code which results in 34 clock cycles.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The code is&amp;nbsp;within&amp;nbsp;the input capure ISR and basically adds the captured value&amp;nbsp;+ a predetermined delay to the output compare registers.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The complication is the 16 bit value to be added. Is there a way in the assembler to indicate high and low bytes?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Jun 2006 23:50:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140028#M2385</guid>
      <dc:creator>FC</dc:creator>
      <dc:date>2006-06-18T23:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140029#M2386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I assume this is for a HC08.&lt;BR /&gt;To access a low byte from a 16 bit variable from assembly, just add 1 to the address of the variable. The HC08 is big endian, and therefore the low byte is at the higher address.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jun 2006 01:38:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140029#M2386</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-06-19T01:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140030#M2387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, FC:&lt;BR /&gt;&lt;BR /&gt;Again , assuming HC08, here is code from one of my GP32 ISRs:&lt;BR /&gt;&lt;PRE&gt;
;
; Add the ICR value to a constant offset and store in the OCR.
;
    lda    TPMC1V+1            ;  3 get the ICR value, low byte
    add    #LOW(time_base)     ;  2 add low byte of update rate
    tax                        ;  1 set aside for load
    lda    TPMC1V              ;  3 get the ICR value, high byte
    adc    #HIGH(time_base)    ;  2 add high byte of update rate
    sta    TPMC0V              ;  3 high byte must always be loaded first
    stx    TPMC0V+1            ;  3 low byte must always be loaded last
;                               = 17 cycles
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;If you are using an HCS08, I believe you no longer have the restriction that the low byte must be loaded last. In that case you can save 1 cycle by eliminating the TAX instruction.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:40:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140030#M2387</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2020-10-29T08:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140031#M2388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello again, FC:&lt;BR /&gt;&lt;BR /&gt;If you can finesse your timer so that the offset can fit in one byte, you could use the HC08s anemic 16-bit add, which can do it in 10 cycles. The offset would have to be either 0 through 127, or FFFF through FF00 (represented as -1 through -128).&lt;BR /&gt;&lt;BR /&gt;Remember to push/pull the H register if you use this, which will add 4 more cycles if you are not already doing a PSHH and PULH.&lt;PRE&gt;
;
; Add the ICR value to a SMALL constant offset and store in the OCR.
;
      ldhx    TPMC1V            ;  4  Get the ICR value
      aix     #time_base        ;  2  Add a small offset to it
      sthx    TPMC0V            ;  4  And store in the OCR
;                                =10 cycles
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:40:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140031#M2388</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2020-10-29T08:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140032#M2389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello FC,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;A slight variation of Rocco's method that does not use the HIGH and LOW directives (not necessarily available for all assemblers).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;lda&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC1V+1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; 3 get the ICR value, low byte&lt;BR /&gt;add&amp;nbsp;&amp;nbsp;&amp;nbsp; #(time_base%256)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;;&amp;nbsp; 2 add low byte of update rate&lt;BR /&gt;tax&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; 1 set aside for load&lt;BR /&gt; lda TPMC1V ; 3 get the ICR value, high byte&lt;BR /&gt;adc&amp;nbsp;&amp;nbsp;&amp;nbsp; #(time_base/256)&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; 2 add high byte of update rate&lt;BR /&gt;sta&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC0V&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; 3 high byte must always be loaded first&lt;BR /&gt;stx&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC0V+1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; 3 low byte must always be loaded last&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jun 2006 11:22:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140032#M2389</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-19T11:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140033#M2390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thanks for the responses.&amp;nbsp; I forgot to mention that its for the HCS08.&lt;/P&gt;&lt;P&gt;The assembler for CW 5.0 returns an error when the +1 is next to channel register. I have seen :smileyshocked: and :1 used before, what does the CW 5.0 assember use?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 05:01:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140033#M2390</guid>
      <dc:creator>FC</dc:creator>
      <dc:date>2006-06-21T05:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140034#M2391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, FC:&lt;BLOCKQUOTE&gt;&lt;HR /&gt;CompilerGuru wrote:&lt;BR /&gt;To access a low byte from a 16 bit variable from assembly, just add 1 to the address of the variable. The HC08 is big endian, and therefore the low byte is at the higher address.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;FC wrote:&lt;BR /&gt;The assembler for CW 5.0 returns an error when the +1 is next to channel register. I have seen :smileyshocked: and :1 used before, what does the CW 5.0 assember use?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;Hmm . . . I could never get CW to work, so I'm still using MCUez. I wonder if this is why CW gives me thousands of errors? Sorry I can't be of more help there. Please let me know what you find out.&lt;BR /&gt;&lt;BR /&gt;Since you use the S08, you can load the high/low bytes in either order, so the code becomes:&lt;PRE&gt;;
; Add the ICR value to a constant offset and store in the OCR.
;
    lda    TPMC1V+1            ;  3 get the ICR value, low byte
    add    #LOW(time_base)     ;  2 add low byte of update rate
    sta    TPMC0V+1            ;  3 load low byte of OCR
    lda    TPMC1V              ;  3 get the ICR value, high byte
    adc    #HIGH(time_base)    ;  2 add carry and high byte of update rate
    sta    TPMC0V              ;  3 load high byte of OCR
;                               = 16 cycles&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:40:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140034#M2391</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2020-10-29T08:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140035#M2392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;The assembler in CW 5.0 uses a :smileyshocked: (high byte) or :1 (low byte).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;ex.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;lda x:1&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 11:31:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140035#M2392</guid>
      <dc:creator>FC</dc:creator>
      <dc:date>2006-06-21T11:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140036#M2393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Oh, God, that's awful!&lt;BR /&gt;&lt;BR /&gt;After twenty-five years of using the + syntax, why would they want to change it? Does that mean that I have over a hundred thousand lines of code that CW won't ever assemble?&lt;BR /&gt;&lt;BR /&gt;If management hears of this, we will be switching to AVRs and PICs. They have been hinting at this for a while now, with only the old code-base holding us back. If they find out Freescale no longer supports our old code, then nothing is keeping them from switching.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 12:13:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140036#M2393</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-06-21T12:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140037#M2394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Rocco, FC,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I have not been able to replicate FC's problem using CW 5.0 assembler.&amp;nbsp; The arithmetic on the register address seems to work fine.&amp;nbsp; I even added spaces before and after the + sign, again without problem (I thought I might have to add parenthesis in this case).&amp;nbsp; In fact, when I placed a colon in lieu of the + sign, I got an assembly error.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I assume that FC is actually using the assembler, rather than inline assembly within the C compiler.&amp;nbsp; The attached sample file assembles correctly using CW 5.0.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 13:03:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140037#M2394</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-21T13:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140038#M2395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks a ton, Mac!&lt;BR /&gt;&lt;BR /&gt;Someday, I will try to get CW to work. But I can now sleep tonight knowing all of my code is not worthless.&lt;BR /&gt;&lt;BR /&gt;I was in a serious panic for a couple of hours, there. Almost drove me to not drink.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 15:16:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140038#M2395</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-06-21T15:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Effecient assembly code to add to the timer channel registers</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140039#M2396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The inline assembler wants offsets to be encoded with the colon syntax&lt;BR /&gt; LDD test:10&lt;BR /&gt; the assembler does expect offsets to be added with a +:&lt;BR /&gt; LDD test+10&lt;BR /&gt;&lt;BR /&gt;My understanding of the idea behind this difference is that for the C compiler, things like "pointer+10" does mean something completely different than for the assembler (the real, non C/HLI assembler).&lt;BR /&gt;&lt;BR /&gt;For the compiler, it means to read the pointer variable from memory and to add to this value 10 times the size of the type, the pointer points to.&lt;BR /&gt;&lt;BR /&gt;For the assembler, it means to add 10 to the address of the pointer label.&lt;BR /&gt;(Well ok labels dont have addresses, they just are addresses, that's actually part of the differences in the meaning between C and asm).&lt;BR /&gt;&lt;BR /&gt;So if the compiler would accept the pointer+10 syntax, then coded like this would behave strange, the HLI and the C part would really not access the same thing:&lt;BR /&gt;&lt;BR /&gt;int * pointer;&lt;BR /&gt;#define ACCESS_POINTER pointer + 10&lt;BR /&gt;void test(void) {&lt;BR /&gt; int a= *(ACCESS_POINTER);&lt;BR /&gt; int b;&lt;BR /&gt; __asm LDD ACCESS_POINTER; // does not compile.&lt;BR /&gt; __asm STD b;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2006 21:17:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Effecient-assembly-code-to-add-to-the-timer-channel-registers/m-p/140039#M2396</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-06-21T21:17:49Z</dc:date>
    </item>
  </channel>
</rss>

