Hi,
I use the P24FJ64GA002 and I have a question: which working registers (W0..W13) need to be unaltered after a called procedure has returned to to caller?
Or in an other way: which registers can be used freely in subroutines without causing problems in their caller?
I see that in routines which do call other routines with parameters, the registers W10, W11 and W12 are pushed at the beginning and popped at the end. Clearly the calling routine assumes that they will be unaltered.
Is there some documentation about this kind of issues?
Thanks in advance!
Preserving working registers when a routine is called?
Preserving working registers when a routine is called?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Preserving working registers when a routine is called?
Hello,
If you are working with asm block, subroutine don't have to worry about working registers.
Caller function will save working registers which should be unaltered, so when the subroutine finish execution, working register which shouldn't have change will get their old value back.
Best regards.
If you are working with asm block, subroutine don't have to worry about working registers.
Caller function will save working registers which should be unaltered, so when the subroutine finish execution, working register which shouldn't have change will get their old value back.
Best regards.
Re: Preserving working registers when a routine is called?
Thanks. And what if I am not working with an asm block?dejan.odabasic wrote:Hello,
If you are working with asm block, subroutine don't have to worry about working registers.
Caller function will save working registers which should be unaltered, so when the subroutine finish execution, working register which shouldn't have change will get their old value back.
Best regards.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: Preserving working registers when a routine is called?
Hi, I can see that an interrupt routine saves the working registers from W0 to W13 (I hope I read the asm code below correctly):
--> Can somebody explain what "PUSH 52" does? Is this "DISICNT" that is saved?
--> Why is W14 not saved?
--> For what is in used in routines? In the mean time i can answer this question myself: as stack frame pointer for local variables.
p.s. I am asking all this apparently silly questions because i am working on an RTOS in mikroPascal.
Code: Select all
PUSH 52
PUSH RCOUNT
PUSH W0
MOV #2, W0
REPEAT #12 <--- will execute the push below 13 times
PUSH [W0++]
--> Why is W14 not saved?
--> For what is in used in routines? In the mean time i can answer this question myself: as stack frame pointer for local variables.
p.s. I am asking all this apparently silly questions because i am working on an RTOS in mikroPascal.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Preserving working registers when a routine is called?
Hello,
There is no need to save W14 as W15, since both values are automatically updated along with linear code execution.
In order to be able to create RTOS, you'll have to save W14 as W15 for every stack splitting(slicing).
Best regards.
In case that you have variables explicitly declared with RX memory specifier, you should take extra care about that variable.Dany wrote:Thanks. And what if I am not working with an asm block?
There is no need to save W14 as W15, since both values are automatically updated along with linear code execution.
In order to be able to create RTOS, you'll have to save W14 as W15 for every stack splitting(slicing).
Best regards.
Re: Preserving working registers when a routine is called?
Thanks!dejan.odabasic wrote:Hello,
In case that you have variables explicitly declared with RX memory specifier, you should take extra care about that variable.Dany wrote:Thanks. And what if I am not working with an asm block?
There is no need to save W14 as W15, since both values are automatically updated along with linear code execution.
In order to be able to create RTOS, you'll have to save W14 as W15 for every stack splitting(slicing).
Best regards.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)