Clear SREG at startup?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just been examining some (old) code (generated by avr gcc 4.3), and I notice that at startup it does three things: clears the r1 register, sets the stack pointer, sets SREG to zero.

 

Why does it set SREG to zero in init? On the processors I'm using SREG is zero (all bits cleared) at startup.

 

What am I missing?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

melbourne wrote:
Why does it set SREG to zero in init?
It needs to clear the I bit (you may be back at 0x0000 for some other reason than power on). It has 0x00 in R1 so it might as well write that to SREG just to clear the I bit. I suppose it could just as easily have used a CLI.