using array declared in "C" code in assembly for S12X

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

using array declared in "C" code in assembly for S12X

2,882 次查看
Vicky
Contributor I
Hi,
I have a requirement which is quite different which i never used earlier.
 
1. Declared a array in a file, test1.c
          unsigned int Store[10]; //Assume unsigned int takes 2 bytes of data
 
2. Now, I need to update store array with content of PC, SP, X, Y and other registers. //Assume, Store[] variable and copy logic would be in same file. I hope it should not be issue either
 
Question:
1. Is it possible to perform step2 above?
2. If its possible, can I have a short example for same.
 
Regards
Vicky
标签 (1)
0 项奖励
3 回复数

737 次查看
EmbeddedCoder
Contributor III
Hi Vicky,
 
It is certainly possible to grab the stack pointer content and store this in an Array via C.
 
I do something similar with the macro below:
 
ASM_STORE_STACK_PTR(pu8_stack);
 
Where the macro is defined as:
 
#define ASM_STORE_STACK_PTR(p_stack)   {__asm STS p_stack;}
 
you will need to check the S12 assembler manual, but there will be other assembler commands to grab the other registers.
 
Good luck!
0 项奖励

737 次查看
EmbeddedCoder
Contributor III
I looked this up for you:
 
STAA will store the Acc A Reg
STAB will store the Acc B Reg
STX will store the Index X Reg
STY will store the Index Y Reg
 
so you can create other macros to store these values for you, as shown below:
 
#define ASM_STORE_ACC_A(p_acc_a)   {__asm STAA p_acc_a;}
#define ASM_STORE_ACC_B(p_acc_b)   {__asm STAB p_acc_b;}
#define ASM_STORE_IX_X(p_x)   {__asm STX p_x;}
#define ASM_STORE_IX_Y(p_y)   {__asm STY p_y;}
 
I'm not sure what storing the program counter will do for you as it will be the address of the place where you store the values?
Do you mean you want to store the program counter contained on the stack (i.e. the calling function)?
0 项奖励

737 次查看
Xbot
Contributor II
0 项奖励