<?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: Using pointers to __far function.</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487979#M12571</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;-CPUHCS12X -D__FAR_DATA -D__NO_FLOAT__ -Lasm=%n.lst -Lasmc=ehpvy -Mb -Onf -Onbf -Onca -Oncn -One -OnP -WmsgSd5909&lt;/P&gt;&lt;P&gt;I am running banked as shown with -Mb.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried putting the called function in a different segment.&amp;nbsp; In the code it now shows up at:&amp;nbsp;&amp;nbsp;&amp;nbsp; OD_ReadTemperature&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; FBA9F3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; PAGE_E0&lt;/P&gt;&lt;P&gt;as expected.&lt;/P&gt;&lt;P&gt;But the compiler generates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;1149:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (* OD_func)(PLONG p) = pDict-&amp;gt;obj-&amp;gt;p.pFunc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 000e ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp; 0,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0010 e64f&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 15,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0012 eee810&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp; 16,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0015 6e83&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STX&amp;nbsp; 3,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0017 6b82&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 2,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;To get at the new page register which is FB it needs to do a LDAB 18,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Instead it's loading the 0x00 in front of the actual address which is 00 A9 F3 FB&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;15,Y is 00 if it's a byte.&amp;nbsp; 16,Y is A9F3 which is where the function lives.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;18,Y would be the page number FB.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Later in the code it calls with the page 00 and crashes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;I still question if the compiler is even generating the correct code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;The stack at that location has have A9 F3 FC.&amp;nbsp;&amp;nbsp; I think it should be A9 F3 FB&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;It doesn't matter if I use the debugger to change the location.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;A CALL [0002,SP] results in 00A9 for the address and F3 for the page.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;If I change the data on the stack, shifting the bytes left one byte, to A9 F3 FB where [0002,SP] is the A9F3 the function call works correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;John&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Apr 2016 09:01:26 GMT</pubDate>
    <dc:creator>jcdammeyer</dc:creator>
    <dc:date>2016-04-08T09:01:26Z</dc:date>
    <item>
      <title>Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487976#M12568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;I am using the 5.1 Codewarrier compiler for the 9S12XDP512.&amp;nbsp; I want to be able to make the compiler generate a call that includes the page register.&amp;nbsp; In the code I have:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Helvetica-Narrow-Oblique;"&gt;&lt;EM style="font-family: Times New Roman;"&gt;void (*__far OD_func)(PLONG p) = pDict-&amp;gt;obj-&amp;gt;p.pFunc;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Helvetica-Narrow-Oblique;"&gt;&lt;EM style=": ; font-family: Arial;"&gt;In the data structure I've declared a union that includes&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: times new roman,times; font-size: 12pt;"&gt;&lt;EM&gt; void (* __far pFunc)(PLONG p)&lt;BR /&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN style="font-size: 12pt; font-family: Helvetica-Narrow-Oblique;"&gt; &lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;From the S12CPUV2.pdf document:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;CALL oprx16,xysp, &lt;EM&gt;page&amp;nbsp;&amp;nbsp;&amp;nbsp; and the opcode should be &lt;/EM&gt;4B xb ee ff pg &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;where xb identifies which index format and which register is used. Trouble is I can't see what xb should be, so that the pg value is included in the instruction.&amp;nbsp; Here's what's generated by the compiler where fb is F3 which matches the index dscription table in the S12CPUV2.pdf document.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Currently the function is in the same page so it doesn't matter.&amp;nbsp; Also this doesn't work.&amp;nbsp; If I replace __far with __near it does work but generates a JSR instead of the call.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; 0035 4bf30002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL&amp;nbsp; [2,SP]&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do a paged call using a function pointer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2016 08:26:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487976#M12568</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2016-04-07T08:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487977#M12569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update on this after further research and testing.&lt;/P&gt;&lt;P&gt;The data structure that holds the pointer can be declared as (* pFunc)(long * p) or as (* __far pFunc)(long * p).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But everything else must be declared as __near.&amp;nbsp; The compiler then generates a JSR instead of a CALL using the correct address for the function. The function must also be declared as __near so an RTS is used to get back.&amp;nbsp; Forget that and it does an RTC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like the compiler thinks the page register is at the front of the address like 0xFC9317 when in memory it's organized as 0x9317FC.&amp;nbsp; Since it does a LDAB to get the 0x93 at 15,Y and then LDX at 16,Y (brings in the 17FC) which is then stored 2 away from the SP.&amp;nbsp; The CALL generated [0002,SP] and the program blows up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As mentioned previously there doesn't seem to be a CALL instruction that loads the Page register along with the PC from registers although the compiler seems to think the B register has the page and it's placed on the stack just before the address.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt; 1145:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (* __far OD_func)(PLONG p) = pDict-&amp;gt;obj-&amp;gt;p.pFunc;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; 000e ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp; 0,X&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; 0010 e64f&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 15,Y&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; 0012 6b82&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 2,SP&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; 0014 ece810&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDD&amp;nbsp; 16,Y&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; 0017 6c83&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STD&amp;nbsp; 3,SP&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;And here's the call to the function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1150:&amp;nbsp; OD_func((PLONG)pDict-&amp;gt;obj-&amp;gt;pReqBuf); // pass result register.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 002f ee80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 0,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0031 ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0033 ec43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDD&amp;nbsp;&amp;nbsp; 3,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0035 4bf30002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL&amp;nbsp; [2,SP]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note the 4B F3 0002 instruction is correct for the CALL [2,SP] and that's a CALL that isn't supposed to have a page value after the 0002. &lt;/P&gt;&lt;P&gt;What I probably should be seeing is 4B F2 00 02 FC which is a 16 bit offset from the SP and should include the page register.&lt;/P&gt;&lt;P&gt;So is the compiler broken or am I doing something wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2016 23:40:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487977#M12569</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2016-04-07T23:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487978#M12570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;first&amp;nbsp; you use &lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;9S12XDP512 which is HCS12x core device, you need to refer S12XCPUV2.pdf instead.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;I will attach it to this thread.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;which memory model do you working with for your project?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;if use banked memory model, functions is allocated by far by default. Can you please check your project memory model?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Jennie Zhang&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2016 07:11:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487978#M12570</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2016-04-08T07:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487979#M12571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;-CPUHCS12X -D__FAR_DATA -D__NO_FLOAT__ -Lasm=%n.lst -Lasmc=ehpvy -Mb -Onf -Onbf -Onca -Oncn -One -OnP -WmsgSd5909&lt;/P&gt;&lt;P&gt;I am running banked as shown with -Mb.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried putting the called function in a different segment.&amp;nbsp; In the code it now shows up at:&amp;nbsp;&amp;nbsp;&amp;nbsp; OD_ReadTemperature&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; FBA9F3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; PAGE_E0&lt;/P&gt;&lt;P&gt;as expected.&lt;/P&gt;&lt;P&gt;But the compiler generates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;1149:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (* OD_func)(PLONG p) = pDict-&amp;gt;obj-&amp;gt;p.pFunc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 000e ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp; 0,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0010 e64f&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 15,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0012 eee810&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp; 16,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0015 6e83&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STX&amp;nbsp; 3,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0017 6b82&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 2,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;To get at the new page register which is FB it needs to do a LDAB 18,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Instead it's loading the 0x00 in front of the actual address which is 00 A9 F3 FB&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;15,Y is 00 if it's a byte.&amp;nbsp; 16,Y is A9F3 which is where the function lives.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;18,Y would be the page number FB.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Later in the code it calls with the page 00 and crashes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;I still question if the compiler is even generating the correct code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;The stack at that location has have A9 F3 FC.&amp;nbsp;&amp;nbsp; I think it should be A9 F3 FB&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;It doesn't matter if I use the debugger to change the location.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;A CALL [0002,SP] results in 00A9 for the address and F3 for the page.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;If I change the data on the stack, shifting the bytes left one byte, to A9 F3 FB where [0002,SP] is the A9F3 the function call works correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt;John&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2016 09:01:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487979#M12571</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2016-04-08T09:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487980#M12572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And another quick follow-up to prove the compiler is generating incorrect code with comments ';;'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1145:&amp;nbsp; DictObjectRead(DICT_PARAM * pDict) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1146:&amp;nbsp; PBYTE rptr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1147:&amp;nbsp; DICT_PARAM * pDictTemp = pDict;&amp;nbsp; // Add this as a place to save the pointer passed in D.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0004 6c87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STD&amp;nbsp;&amp;nbsp; 7,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1148:&amp;nbsp; // If the object is valid, control code must be something other than 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1149:&amp;nbsp; if (pDict-&amp;gt;obj-&amp;gt;ctl) { // Process any functionally defined objects&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0006 b745&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TFR&amp;nbsp;&amp;nbsp; D,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0008 ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 000a e64c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 12,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 000c c100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMPB&amp;nbsp; #0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 000e 2776&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEQ&amp;nbsp;&amp;nbsp; *+120 ;abs = 0086&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1150:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (* OD_func)(PLONG p) = pDict-&amp;gt;obj-&amp;gt;p.pFunc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0010 ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0012 e64f&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 15,Y&amp;nbsp; ;; Loads 0x00 rather than page register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0014 eee810&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 16,Y&amp;nbsp; ;; Loads offset to function&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0017 6e85&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STX&amp;nbsp;&amp;nbsp; 5,SP&amp;nbsp; ;; Stores offset to wrong location &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0019 6b84&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 4,SP&amp;nbsp; ;; because it thinks page has to be in front of offset. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1151:&amp;nbsp; asm ;; Above code doesn't work so we do it in assembler instead.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1152:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 7,SP&amp;nbsp; ; restore * pDict&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 001b ee87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 7,SP&amp;nbsp; ;; Previous code trashed X so we get the copy back&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1153:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&amp;nbsp;&amp;nbsp; ; point into pDict&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 001d ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1154:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 18,Y&amp;nbsp; ; Get the page register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 001f e6e812&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDAB&amp;nbsp; 18,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1155:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 16,Y&amp;nbsp; ; Get the offset into that page&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0022 eee810&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 16,Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1156:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STX&amp;nbsp;&amp;nbsp; 4,SP&amp;nbsp; ; Store the offset&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0025 6e84&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STX&amp;nbsp;&amp;nbsp; 4,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1157:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 6,SP&amp;nbsp; ; followed by the page register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0027 6b86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STAB&amp;nbsp; 6,SP&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; 1158:&amp;nbsp; }&amp;nbsp; Working assembler code completed&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Now let's look at how it's used.&amp;nbsp; This code as generated by the compiler works now.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;1163:&amp;nbsp; OD_func((PLONG)pDict-&amp;gt;obj-&amp;gt;pReqBuf); // pass result register.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0041 ee80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDX&amp;nbsp;&amp;nbsp; 0,SP&amp;nbsp; ;; Get our parameter to pass.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0043 ed00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDY&amp;nbsp;&amp;nbsp; 0,X&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0045 ec43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDD&amp;nbsp;&amp;nbsp; 3,Y&amp;nbsp;&amp;nbsp; ;; Pass the parameter in the D register&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 10pt;"&gt;&amp;nbsp; 0047 4bf30004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL&amp;nbsp; [4,SP]&amp;nbsp; ;; The opcode is correct and the call is to the function offset which is followed by the page value&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2016 17:41:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487980#M12572</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2016-04-08T17:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487981#M12573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for your reply.&lt;/P&gt;&lt;P&gt;can you please send me your project for this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Jennie Zhang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 12:13:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487981#M12573</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2016-04-25T12:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using pointers to __far function.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487982#M12574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Here is the Project File.&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 15:30:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Using-pointers-to-far-function/m-p/487982#M12574</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2016-04-25T15:30:48Z</dc:date>
    </item>
  </channel>
</rss>

