SREG Transfer bit / avr-libc

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

Is the transfer bit in SREG a general purpose bit usable by the application developer or does avr-libc reserve use of the bit?

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

The floating-point routines (at least in avr-libc up to 1.4.x) use it
internally.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

There was a similar discussion before. Look here.

Regards
Sebastian

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

dl8dtl wrote:
The floating-point routines (at least in avr-libc up to 1.4.x) use it
internally.

GCC can use it, but only in some corner cases (loading non-immediate registers etc, shift 16 bit registers.) Note that the instructions concerned with T flag also include BLT and BLD not just SET and CLT.
And GCC is not saving/restoring the bit. So using it is on your own risk!

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

Quote:
And GCC is not saving/restoring the bit.

Except that anything that saves/restores SREG should be safe, so I'm not really sure how dangerous it would be to use it.

Regards,
Steve A.

The Board helps those that help themselves.

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

wvangulik wrote:

.... So using it is on your own risk!

Since the SREG is saved/restored between calls it should be safe within that aspect. What I was worried about is functions in avr-libc using the T-bit to transfer info between function calls. I know Keil used a flag bit in the status register of the 8051 to pass info between functions but didn't document it so peoples code would end up breaking when the tried to use the flag bit.

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

> Since the SREG is saved/restored between calls

No, only within interrupt handlers. Calling another function doesn't
preserve SREG (but wouldn't modify the T bit either).

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.