<?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: Inline Assembly Troubles (Such a Noob Problem) in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125456#M635</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;void WriteFlash(void) {&lt;BR /&gt; byte temp = 0x00;&lt;BR /&gt;&lt;BR /&gt; if ((FSTAT &amp;amp; 0x10) != 0) {&lt;BR /&gt; FSTAT |= 0x30;&lt;BR /&gt; }&lt;BR /&gt; asm {&lt;BR /&gt; //LDA #$CC&lt;BR /&gt; //STA $1600&lt;BR /&gt; LDA #$20&lt;BR /&gt; STA FCMD&lt;BR /&gt; LDA #$80&lt;BR /&gt; STA FSTAT&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; WFLOOP:&lt;BR /&gt; LDA FSTAT&lt;BR /&gt; LSLA&lt;BR /&gt; BPL WFLOOP &lt;BR /&gt; }&lt;BR /&gt;} // end WriteFlash&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yes, I know it works.. if i use &lt;BR /&gt;asm{&lt;BR /&gt;LCD #$CC&lt;BR /&gt;STA $1600&lt;BR /&gt;}&lt;BR /&gt;WriteFlash()&lt;BR /&gt;&lt;BR /&gt;the value of 0xCC will be written to location 0x1600&lt;P&gt;Message Edited by mjcoury on &lt;SPAN class="date_text"&gt;2006-08-01&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:58 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Aug 2006 21:56:57 GMT</pubDate>
    <dc:creator>mjcoury</dc:creator>
    <dc:date>2006-08-01T21:56:57Z</dc:date>
    <item>
      <title>Inline Assembly Troubles (Such a Noob Problem)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125454#M633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having some trouble with my inline assmebly. to preface everthing, this is my routine to read memory out to the serial port&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void ReadRamOut(word iMemory, int iByte) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int i = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;char *memory_ptr;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;memory_ptr = (char*)iMemory;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for( i=0; i&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SCIStartTransmit(*(memory_ptr+i));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} // end for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} // end ReadRamOut&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code to write to flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;DisableInterrupts&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memory_ptr = (char*)iMemory;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for( i=0; i&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ctemp = gu8SCIData[i];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;asm{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LDA ctemp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STA memory_ptr&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WriteFlash();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memory_ptr++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} // end for loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iMode = 0x00;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gu8SCIIndex = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EnableInterrupts&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I show the ReadRamOut routine because that method of pointing to a memory location has worked for me... so I assumed it would work again for the inline assembly....&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Now assume iMemory = 0x1600. instead of writing ctemp to the memory location 0x1600 it writes over the 0x1600 with the contents of ctemp. I have tried a few different combinations of iMemory and memory_ptr to get this to work.. Any Ideas?&lt;/SPAN&gt;&lt;P&gt;Message Edited by mjcoury on &lt;SPAN class="date_text"&gt;2006-08-01&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:58 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 20:57:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125454#M633</guid>
      <dc:creator>mjcoury</dc:creator>
      <dc:date>2006-08-01T20:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Assembly Troubles (Such a Noob Problem)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125455#M634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;If you just want to transfer the contents of gu8SCIData[i] into the location pointed to by memory_ptr, then you can just do this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*memory_ptr = gu8SCIData[i];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;There is really no need to fuss with the inline assembly - but the reason it might be failing could be that you are erasing the contents of the accumulator when they are needed.&amp;nbsp; Try this assembly instead:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PSHA&lt;/DIV&gt;&lt;DIV&gt;LDA ctemp&lt;/DIV&gt;&lt;DIV&gt;STA memory_ptr&lt;/DIV&gt;&lt;DIV&gt;PULA&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What is in the WriteFlash() function?&amp;nbsp; Do you know that works?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 21:25:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125455#M634</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-08-01T21:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Assembly Troubles (Such a Noob Problem)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125456#M635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;void WriteFlash(void) {&lt;BR /&gt; byte temp = 0x00;&lt;BR /&gt;&lt;BR /&gt; if ((FSTAT &amp;amp; 0x10) != 0) {&lt;BR /&gt; FSTAT |= 0x30;&lt;BR /&gt; }&lt;BR /&gt; asm {&lt;BR /&gt; //LDA #$CC&lt;BR /&gt; //STA $1600&lt;BR /&gt; LDA #$20&lt;BR /&gt; STA FCMD&lt;BR /&gt; LDA #$80&lt;BR /&gt; STA FSTAT&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; NOP&lt;BR /&gt; WFLOOP:&lt;BR /&gt; LDA FSTAT&lt;BR /&gt; LSLA&lt;BR /&gt; BPL WFLOOP &lt;BR /&gt; }&lt;BR /&gt;} // end WriteFlash&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yes, I know it works.. if i use &lt;BR /&gt;asm{&lt;BR /&gt;LCD #$CC&lt;BR /&gt;STA $1600&lt;BR /&gt;}&lt;BR /&gt;WriteFlash()&lt;BR /&gt;&lt;BR /&gt;the value of 0xCC will be written to location 0x1600&lt;P&gt;Message Edited by mjcoury on &lt;SPAN class="date_text"&gt;2006-08-01&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:58 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 21:56:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125456#M635</guid>
      <dc:creator>mjcoury</dc:creator>
      <dc:date>2006-08-01T21:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Assembly Troubles (Such a Noob Problem)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125457#M636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;as rhinoceroshead already pointed out, such simple assignments can be made easely in C, no need for HLI.&lt;BR /&gt;The HLI assembly instruction "STA memory_ptr" clearly stores the content of A into the high byte of the local variable memory_ptr. If you want to store to the place were memory_ptr points to, you have to load it into H/X, and then do a STA 0,X. Just using C is much simpler tough:&lt;BR /&gt;*memory_ptr= ctemp;&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 23:59:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Inline-Assembly-Troubles-Such-a-Noob-Problem/m-p/125457#M636</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-08-01T23:59:50Z</dc:date>
    </item>
  </channel>
</rss>

