title: Accessing array by pointer to an array in avr assembly
body: <p>I'm programming an AVR microcontroller using a mix of C and ASM but I'm having a bit of trouble. </p>
  
  <p>I have the following code in my C code:</p>
  
  <pre><code>uint8_t amplitudes32[32] = {.. constant values ..};
  uint8_t amplitudes64[64] = {.. constant values ..}
  uint8_t* amplitudes;
  </code></pre>
  
  <p>(amplitudes32/64 are basically look up tables)</p>
  
  <p>And some times I want amplitudes to be equal to amplitudes32 and sometimes want it to be equal to  amplitudes64.</p>
  
  <p>I'm doing this by going </p>
  
  <p><code>amplitudes = amplitudes32;</code> in my c code.</p>
  
  <p>Then, in my ASM interrupt routine I want to read in the address of the array like this:</p>
  
  <pre><code>ldi r30, lo8(amplitudes)    
  ldi r31, hi8(amplitudes)  
  </code></pre>
  
  <p>I then do some more instructions to get the value of the array at a certain index out to a particular port. However, when I check the output it's not working properly and I get something I'm not expecting. I get the same thing no matter what the array is made up of.. it's the same even when <code>amplitudes</code> is pointing to an array of all zeros.</p>
  
  <p>If I change the assembly code to </p>
  
  <pre><code>ldi r30, lo8(amplitudes64)      
  ldi r31, hi8(amplitudes64) 
  </code></pre>
  
  <p>Then it works as expected. But like I said, I need to have a different look up table at different times and because of speed issues I can't make that decision within the interrupt routine so it'd be nice if I could have an array 'variable' that I could change in my C code which the interrupt then uses.</p>
  
  <p>What am I doing wrong?</p>