<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - instruction set tag</title>
  <link>http://bleaklow.com:80/tags/instruction set/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 29 Feb 2012 20:50:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>ATMega registers and memory ranges</title>
    <link>http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html</link>
    <description>
          &lt;p&gt;
The AVR family has a reasonably complex register and memory architecture, with:
&lt;ul&gt;
&lt;li&gt;Multiple address spaces&lt;/li&gt;
&lt;li&gt;Registers that can be accessed directly and via the memory address space&lt;/li&gt;
&lt;li&gt;Register pairs that are used as memory indexes&lt;/li&gt;
&lt;li&gt;Restrictions on which registers can be loaded directly with constant values&lt;/li&gt;
&lt;li&gt;Some IO ports that appear in both the memory and IO address spaces, but with different addresses in each&lt;/li&gt;
&lt;li&gt;Some IO ports that are only accessible via the memory address space&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
In addition, the gcc compiler has conventions governing which registers it uses for what purpose, for example:
&lt;/p&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Which registers it uses for purposes such as storing temporary values and zero&lt;/li&gt;
&lt;li&gt;Which registers it uses for passing and returning arguments&lt;/li&gt; 
&lt;li&gt;Which registers it uses as a stack frame pointer&lt;/li&gt;
&lt;li&gt;Which registers are saved by the caller on entry to a subroutine and which ones have to be saved by the callee&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
When I&#039;m reading the assembler output of gcc I find it helpful to have a table to remind me which registers are being used for what, and why.  The information is not exactly well-explained in the AVR documentation and I&#039;ve not been able to find all the information in once place on the Internet, so I&#039;ve drawn up the following quick-reference table to remind me of what goes where:
&lt;p&gt;
&lt;a href=&#034;/files/2011/ATmegaRegMem.pdf&#034;&gt;&lt;img src=&#034;/images/2011/ATmegaRegMem.png&#034; alt=&#034;ATMega registers and address ranges&#034;/&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Click on the image for a PDF copy of the table.  I hope you find this useful, corrections and suggestions welcome - please leave a comment below!
&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc8271.pdf&#034;&gt;ATmega328P datasheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc2549.pdf&#034;&gt;ATmega1289 datasheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc0856.pdf&#034;&gt;8-bit AVR instruction set&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.nongnu.org/avr-libc/user-manual/index.html&#034;&gt;avr-libc documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html</guid>
    <pubDate>Sun, 10 Apr 2011 16:28:50 GMT</pubDate>
  </item>
  </channel>
</rss>

