Where does __SREG__ get defined?

I can reference sreg by SREG in inline assembly, but I didn't get the location where it is defined. Is it compiler defined variable?

it is simply a memory location.

/* Status Register */
#ifndef SREG
#  if __AVR_ARCH__ >= 100
#    define SREG _SFR_MEM8(0x3F)
#  else
#    define SREG _SFR_IO8(0x3F)
#  endif
#endif

Found in D:\arduino-1.0.5\hardware\tools\avr\avr\include\avr\boot.h

Can't find a define for SREG yet, but it would be the same memory location.

Thanks for the hint. The address makes sense, but I am interested in why SREG cannot be used in inline assembly directly, instead SREG is necessary.

pYro_65:
it is simply a memory location.

/* Status Register */

#ifndef SREG

if AVR_ARCH >= 100

define SREG _SFR_MEM8(0x3F)

else

define SREG _SFR_IO8(0x3F)

endif

#endif




Found in D:\arduino-1.0.5\hardware\tools\avr\avr\include\avr\boot.h

Can't find a define for __SREG__ yet, but it would be the same memory location.

Can you make a pointer to use.

As SREG is just a number literal, maybe you just need a place holder, which is what I assume SREG is.

uint8_t *u =( uint8_t* )  0x3F;

or

uint8_t &u = *( uint8_t* )  0x3F;

but it may be a linker generated value like __brkval and __heap_start

Yes, the real SREG is compiler defined. As below gcc patch shows.

// avr\source\gcc\4.3.2\52-gcc-4.3.2-xmega-v9.patch
 /*  fprintf (asm_out_file, "\t.arch %s\n", avr_mcu_name);*/
   fputs ("__SREG__ = 0x3f\n"
 	 "__SP_H__ = 0x3e\n"
 	 "__SP_L__ = 0x3d\n", asm_out_file);