Mixing C with Assembler: Assembly code before push instructions in a function

PeterH:

GreyGnome:
I would like to preserve the state of a register very quickly when the interrupt takes place.

I guess you mean you want to preserve the state of an I/O register at the earliest possible point in an ISR.

Exactly! You hit the nail on the head. I am writing a library and I am preserving the state of an I/O register- ostensibly at the time of the interrupt- but with all the push instructions, it takes place some 4 microseconds (I figure) after the actual interrupt.

Have you thought of a way to do that without using any processor registers? Since you can't know what processor registers are in use you mustn't use them until you have preserved their state so that they can be restored afterwards.

Not really. I am aware of this:

Register r0 may be freely used by your assembler code and need not be restored at the end of your code. It's a good idea to use tmp_reg and zero_reg instead of r0 or r1, just in case a new compiler version changes the register usage definitions.

So I believe I can safely use r0. All I need is to use the in instruction, then save that register to RAM, and I should be good to go.