push and pop CCR register on stack

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

push and pop CCR register on stack

Jump to solution
1,281 Views
grzegorzK
Contributor III

Hi

 

I use MC9S08DZ60. I would like to get functionality to push and pop CCR register on/from stack.

Something similar as quoted macros below (from PE) but CCR saved on stacked variable, not global variable as in example from PE

 

 

#define SaveStatusReg()       { asm PSHA; asm TPA; asm SEI; asm STA CCR_reg; asm PULA; }

#define RestoreStatusReg()   { asm PSHA; asm LDA CCR_reg; asm TAP; asm PULA; }

 

where CCR_reg is global variable, I would like to use auto variable located on stack,

 

e.g:

#define SaveStatusReg()       volatile byte CCR_stack;  asm PSHA; asm TPA; asm SEI; asm XXX CCR_stack; asm PULA;



Could someone help me?


Best Regards

/Greg


Labels (1)
0 Kudos
Reply
1 Solution
992 Views
kef2
Senior Contributor V

#define SaveStatusReg()       char  CCR_stack; asm PSHA; asm TPA; asm SEI; asm STA CCR_reg; asm PULA;

#define RestoreStatusReg()   { asm PSHA; asm LDA CCR_reg; asm TAP; asm PULA; }

Should work, provided SaveStatusReg() in { } block comes immediately after variables. Like

void foo()

{

int a;

char b;

    // only variables here

    SaveStatusReg();

   ...

}

or

void foo()

{

int a;

   a++;

   a--;

   {

   char inner_block_vars;

       SaveStatusReg();

       ....

        RestoreStatusReg();

   }

   ...

}

View solution in original post

0 Kudos
Reply
4 Replies
993 Views
kef2
Senior Contributor V

#define SaveStatusReg()       char  CCR_stack; asm PSHA; asm TPA; asm SEI; asm STA CCR_reg; asm PULA;

#define RestoreStatusReg()   { asm PSHA; asm LDA CCR_reg; asm TAP; asm PULA; }

Should work, provided SaveStatusReg() in { } block comes immediately after variables. Like

void foo()

{

int a;

char b;

    // only variables here

    SaveStatusReg();

   ...

}

or

void foo()

{

int a;

   a++;

   a--;

   {

   char inner_block_vars;

       SaveStatusReg();

       ....

        RestoreStatusReg();

   }

   ...

}

0 Kudos
Reply
992 Views
grzegorzK
Contributor III

Yes, works (if somne want use it, be cerfull with typo in name of auto variable)

Thank You.

0 Kudos
Reply
991 Views
tonyp
Senior Contributor II

ASM8 uses the PSHCC and PULCC internal macros which correspond to this:

[from ASM8 manual http://www.aspisys.com/asm8.pdf]:

PSHCC (PUSH CCR)

-----------------------------

PSHA

PSHA

TPA

STA 2,SP

TAP

PULA

PULCC (PULL CCR)

----------------------------

PSHA

LDA 2,SP

TAP

PULA

AIS #1


PSHCC is careful to not change the CCR bits on push.


Hope this helps.

0 Kudos
Reply
992 Views
grzegorzK
Contributor III

hi

thank you for your replay.

I do not understand what means "internal", internal of what? I should mention that I use CW10.6 envornoment for build target. I am looking macro for use in C module as in Processor Expert example.

Regards

/GReg

0 Kudos
Reply