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
Solved! Go to Solution.
#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();
}
...
}
#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();
}
...
}
Yes, works (if somne want use it, be cerfull with typo in name of auto variable)
Thank You.
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.
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