so i usually combine C with inline assembly but there is something that i cannot quite figure ,
the main registers (all of them) r0 -> r31 so if i set a register to a certain value in the program setup , i want that state to be maintained during the whole program even after the "asm volatile" and after setting thr register , i am not using any C functions or any other programs , am just using inline assembly and an ISR routine , so i know that at the beginning of the ISR the system places some code and at the end to , so that the state of the system get's preserved , i am using the ISR_NAKED attribute so that should not happen , so i want to use the "r17" register as a counter , every time the ISR is triggered it increments the already set value in the r17 register , that's why i want to know if the system alters registers in a random way in between of ISRs ? , the loop program is just an empty loop ( while(true); ) .
I looked quite carefully, but couldn't see a question mark.
What is a "voided loop" ?
AWOL:
I looked quite carefully, but couldn't see a question mark.What is a "voided loop" ?
while(true) {}
question mark added ![]()
Not, the registers are not used randomly. The registers have a certain role and C compiler has defined rules for registers use and it is quite complicated. You can find more about it on web, unfortunately I couldn't find complex info on one place.
The number of registers is limited and it is nonsense to dedicate one register to specific use for forever. Prologue and epilogue code in functions ensures continuity before and after function call in register values. If you are using naked function you have to ensure correct register handling yourself, to save previous value before and restore after your code.
I don't know a solution to the problem, or even if there is a solution.
But it seems to me that mixing Assembler code with Arduino code they way you are hoping to is a bit like asking a roomful of school children to be quiet.
...R
... and maybe also:
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_regbind
http://www.nongnu.org/avr-libc/user-manual/inline_asm.html
thank you very much guys .
Robin ... your choice of words is highly remarkable , as always ![]()
though in the loop , there is almost no code running , so it's almost like the only runnig code would be the ISR ... how will that register be altered ?
amine2:
thank you very much guys .
Robin ... your choice of words is highly remarkable , as alwaysthough in the loop , there is almost no code running , so it's almost like the only runnig code would be the ISR ... how will that register be altered ?
An ISR, by definition, must NOT modify any registers. Any registers it uses MUST be properly saved and restored.
Regards,
Ray L.
what i mean is the opposite , i am using a NAKED_ISR , i do not want the program to alter the registers set by the ISR , though this should not be done , registers are not ment to be used like this , a solution to this would be to reserve some space in SRAM for the contents i want to preserve then just access and alter them when i need to do so . it will be a couple of clocks slower than the rapid access of registers , but it will do just fine
Or, you could use a timer configured for external input.
You are aware that there could be other stuff occurring inside your empty loop:
int main(void) {
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun)
serialEventRun();
}
return 0;
}
Furthermore, the use of "volatile" in conjunction with inline "asm" does not guarantee the compiler will not muck with your code. To accomplish your goals you probably need to write your program completely in assembler.