Question regarding asm syntax in ATmegaBOOT_168.c

Hello everybody. Having a look at the ATmegaBOOT_168.c source code in Arduino release 1.6.5, I have difficulties in understanding the following :

Inside the forever loop in the code part dedicated to reception of a 'd' char (write memory), I can find the following code :

"wait_spm1:     \n\t"
"lds    r16,%0      \n\t"   //Wait for previous spm to complete
"andi   r16,1           \n\t"
"cpi    r16,1           \n\t"
"breq   wait_spm1       \n\t"
"ldi    r16,0x03    \n\t"   //Erase page pointed to by Z
"sts    %0,r16      \n\t"
"spm            \n\t"

As far as I understand the code and the associated comments the first part is dedicated to waiting the SPMEN bit of the SPMCSR register being 0 and the second part to setting the SPMEN and PGERS bits to 1 to erase the memory page when SPM instruction is given.

My question is : in the LDS R16,%0 and STS %0,R16 instructions %0 seems to refer to the SPMCSR register address. But I don't understand the relationship in beetween %0 and 0x37 (0x57) that is supposed to be the register address according to the ATMega328p datasheet. Is there somewhere a %0 definition I'm missing or is there any % syntax asm specifities ?

Thanks for your help.

That code is part of an asm() statement that begins on line 588 and ends on line 687. The last few lines of the statement describe the output operands, the input operands, and the clobbers. For the ATMega328, the first output operand is "=m" (SPMCSR)In typical C fashion, the first operand is indexed as 0, so, where "%0" appears, it references that value. The constraint character, "m," means that the operand is a memory address.

AVR inline assembler is, to me at least, hard to understand, and often counter-intuitive. For example, I don't know why a memory address would be an "output operand." Maybe input and output operands are described from the compiler's vantage point, rather than mine. The online descriptions that I've seen aren't particularly easy to follow. The most effective for me has been this one, from AVRfreaks.


tmd3 and JimEli thanks to both of you... After reading the documents attached to the links included in your messages I have quite a clear vision of operand's use...