Preserving working registers when a routine is called?

Beta Testing discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Preserving working registers when a routine is called?

#1 Post by Dany » 12 Jun 2013 11:45

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! :D :D
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)

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Preserving working registers when a routine is called?

#2 Post by dejan.odabasic » 13 Jun 2013 13:52

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.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Preserving working registers when a routine is called?

#3 Post by Dany » 13 Jun 2013 17:44

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.
Thanks. And what if I am not working with an asm block?
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)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Preserving working registers when a routine is called?

#4 Post by Dany » 14 Jun 2013 20:51

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):

Code: Select all

        PUSH        52
        PUSH        RCOUNT
        PUSH        W0
        MOV        #2, W0
        REPEAT        #12             <--- will execute the push below 13 times
        PUSH        [W0++]
--> 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.
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)

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Preserving working registers when a routine is called?

#5 Post by dejan.odabasic » 18 Jun 2013 13:21

Hello,
Dany wrote:Thanks. And what if I am not working with an asm block?
In case that you have variables explicitly declared with RX memory specifier, you should take extra care about that variable.

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.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Preserving working registers when a routine is called?

#6 Post by Dany » 18 Jun 2013 16:11

dejan.odabasic wrote:Hello,
Dany wrote:Thanks. And what if I am not working with an asm block?
In case that you have variables explicitly declared with RX memory specifier, you should take extra care about that variable.

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.
Thanks! :D :D
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)

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing”