Assembler within C Code, push necessary ?

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

Hello,

I'm just new to using gcc with the AVRs, but it's really
great !

One question: If I call assembler functions from within
my C sourcecode (functions declared as external and
contained in a separate .s file), do I have to 'push'
registers I use within my assembler functions on the
stack ?? Or is the register save'ing and restoring done
by gcc ??

Thanks you very much !!

Markus

admin's test signature
 

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

Hi Markus!

The following is a part of the GCC docu, I hope it will help you:

- Call-used registers (r18-r27, r30-r31):
May be allocated by gcc for local data. You MAY use them freely in assembler subroutines. Calling C subroutines can clobber any of them - the caller is responsible for saving and restoring.

- Call-saved registers (r2-r17, r28-r29):
May be allocated by gcc for local data. Calling C subroutines leaves them unchanged. Assembler subroutines are responsible for saving and restoring these registers, if changed. r29:r28 (Y pointer) is used as a frame pointer (points to local data on stack) if necessary.

- Fixed registers (r0, r1):
Never allocated by gcc for local data, but often used for fixed purposes: r0 - temporary register, can be clobbered by any C code (except interrupt handlers which save it), MAY be used to remember something for a while within one piece of assembler code
r1 - assumed to be always zero in any C code, MAY be used to remember something for a while within one piece of assembler code, but MUST then be cleared after use ("clr r1"). This includes any use of the [f]mul[s[u]] instructions, which return their result in r1:r0. Interrupt handlers save and clear r1 on entry, and restore r1 on exit (in case it was non-zero).

Best regards, Klaus

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

Hello Klaus,

yes, this helps - thanks for pointing me to this
information.

Markus

admin's test signature