title: Atmel Studio AVR operand out of range
body: <p>I am working on a small program to learn how to mix C and Assembly in Atmel Studio GCC.  Basically I am writing a C program to initiate the stack pointer in assembly.  When I build it I keep getting an error "Operand out of range".  I've initiated stack pointers many times in programs but can't get it to work in the ".s" file of this program.  I've gotten the program to work with different register in the ".s" file so I don't think it's the connection between the two files.  Any help would be appreciated.</p>
  
  <p>Main.c:</p>
  
  <pre><code>    #define F_CPU 16000000
  
      #include &lt;avr/io.h&gt;
      #include &lt;util/delay.h&gt;
  
      extern void setStackPointer(void);
  
      int main(void)
      {
          DDRB |= 0x20;
          setStackPointer();
          while (1) 
          {
              PORTB = 0x20;
              _delay_ms(500);
              PORTB = 0x00;
              _delay_ms(500);
          }
      }
  </code></pre>
  
  <p>Assembler1.s:</p>
  
  <pre><code>    #define _SFR_ASM_COMPAT 1
      #define _SFR_OFFSET 0
      #include &lt;avr/io.h&gt;
  
      .global setStackPointer
  
      setStackPointer:
                  ldi r18, lo8(RAMEND-0x20)
                  out SPL, R18
                  ldi R18, hi8(RAMEND-0x20)
                  out SPH, R18
                  ret
  </code></pre>