<story><title>Rust on the MOS 6502: Beyond Fibonacci</title><url>https://gergo.erdi.hu/blog/2021-09-18-rust_on_the_mos_6502__beyond_fibonacci/</url></story><parent_chain><item><author>cmrdporcupine</author><text>I haven&amp;#x27;t looked at this closely, but 6502 &lt;i&gt;really&lt;/i&gt; doesn&amp;#x27;t lend itself to C compilation. Three registers, only one of which works with the ALU, awkward immovable stack, etc.&lt;p&gt;The 65816 is a better target (moveable direct page and stack and some wider registers), but also awkward with its register mode switching.</text></item><item><author>royjacobs</author><text>That is so cool. I saw some posts about LLVM-MOS a while ago, but at that point I thought it would be just another in a fairly long list of attempts to try and get LLVM to output 6502 instructions.&lt;p&gt;I never expected it to come together this well! Especially considering that the author of the article mentions there were so many issues with LLVM-AVR, you&amp;#x27;d expect them to exist in LLVM-MOS as well. Apparently not! I guess the code quality will only improve from here on out, the loop at the bottom of the article does seem like it is not as optimal as it could be :)</text></item></parent_chain><comment><author>gergoerdi</author><text>From what I understand, LLVM-MOS treats large parts of the zero page as virtual (&amp;quot;imaginary&amp;quot;) registers, so you have no shortage of that (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;llvm-mos.org&amp;#x2F;wiki&amp;#x2F;Imaginary_registers&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;llvm-mos.org&amp;#x2F;wiki&amp;#x2F;Imaginary_registers&lt;/a&gt;). Then, &lt;i&gt;sufficiently advanced compiler&lt;/i&gt; technology improves the stack situation (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;llvm-mos.org&amp;#x2F;wiki&amp;#x2F;C_calling_convention&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;llvm-mos.org&amp;#x2F;wiki&amp;#x2F;C_calling_convention&lt;/a&gt;).</text></comment>
<story><title>Rust on the MOS 6502: Beyond Fibonacci</title><url>https://gergo.erdi.hu/blog/2021-09-18-rust_on_the_mos_6502__beyond_fibonacci/</url></story><parent_chain><item><author>cmrdporcupine</author><text>I haven&amp;#x27;t looked at this closely, but 6502 &lt;i&gt;really&lt;/i&gt; doesn&amp;#x27;t lend itself to C compilation. Three registers, only one of which works with the ALU, awkward immovable stack, etc.&lt;p&gt;The 65816 is a better target (moveable direct page and stack and some wider registers), but also awkward with its register mode switching.</text></item><item><author>royjacobs</author><text>That is so cool. I saw some posts about LLVM-MOS a while ago, but at that point I thought it would be just another in a fairly long list of attempts to try and get LLVM to output 6502 instructions.&lt;p&gt;I never expected it to come together this well! Especially considering that the author of the article mentions there were so many issues with LLVM-AVR, you&amp;#x27;d expect them to exist in LLVM-MOS as well. Apparently not! I guess the code quality will only improve from here on out, the loop at the bottom of the article does seem like it is not as optimal as it could be :)</text></item></parent_chain><comment><author>Someone</author><text>Not only C, any language that thinks there’s other things than global state.&lt;p&gt;If all your functions are &lt;i&gt;void foo(void)&lt;/i&gt; and you don’t use local variables (or your language doesn’t support recursion, in which case all locals can be given a fixed address), targeting 6502 is fine (it also helps if you avoid floating point, use 8-bit variables where possible, etc)&lt;p&gt;Not supporting recursion also means you can statically compute maximum stack depth. That way, you can avoid linking code that would overflow the stack.</text></comment>