|
|
 | | From: | mann! | | Subject: | help...storing user registers to stack....as a programming practice | | Date: | 18 Jan 2005 00:17:50 -0800 |
|
|
 | hi ,
as a programming practice , shd all the user registers be saved to the stack in the interrupt handler( in assembly) before goign to the interrupt service routine?
in the interrupt files provided by atmel , the follwing code
IF "$reg" = "" stmfd sp!, { r1-r3, r12, r14} ELSE stmfd sp!, { r1-r3, $reg, r12, r14} ENDIF
....saves registers r1-r3 , the specified registers and r12 on to the stack ....now some thigns i cant figure out...
1) as a practice , shoudlnt user register stacking be left to the c code so that the person writing it does not need to refer to the handler routine to generate most efficient code?
2) if any (all?) regusters are stacked before entering the subroutine , doesnt it eliminate the option of the subroutine passing back some values in registers?
............help!!
thanks
MNN
|
|
 | | From: | Not Really Me | | Subject: | Re: help...storing user registers to stack....as a programming practice | | Date: | Tue, 18 Jan 2005 09:08:06 -0700 |
|
|
 | mann! wrote: > hi , > > as a programming practice , shd all the user registers be saved to the > stack in the interrupt handler( in assembly) before goign to the > interrupt service routine? > > in the interrupt files provided by atmel , the follwing code > > IF "$reg" = "" > stmfd sp!, { r1-r3, r12, r14} > ELSE > stmfd sp!, { r1-r3, $reg, r12, r14} > ENDIF > > ...saves registers r1-r3 , the specified registers and r12 on to the > stack ....now some thigns i cant figure out... > > 1) as a practice , shoudlnt user register stacking be left to the c > code so that the person writing it does not need to refer to the > handler routine to generate most efficient code? > > 2) if any (all?) regusters are stacked before entering the subroutine > , doesnt it eliminate the option of the subroutine passing back some > values in registers? > > ...........help!! > > thanks > > MNN
In the Atmel example they are saving away the registers that the C compiler uses. The $reg values allows adding some optional registers that you may be modifying in assembly language.
1.) If you are writing the interrupt routine in assembly language there is no direct way for the compiler to save the registers for you.
2.) Interrupt routines NEVER should return values in registers. Interrupt functions are always defined as void returns. You can modify global variables that tell your code something happened under interrupt, but by design, interrupt routines happen asynchronously to the rest of the code, literally "interrupting" normal code execution, thus modifying a register will corrupt the interrupted code.
Scott
|
|
 | | From: | mann! | | Subject: | Re: help...storing user registers to stack....as a programming practice | | Date: | 18 Jan 2005 20:57:20 -0800 |
|
|
 | ya thats enlightening...thanks a lot!
|
|
|