How to get a CPU register value in a c file?

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

How to get a CPU register value in a c file?

4,194 次查看
admin
Specialist II
Hello,
 
I want to get the SP and IX value in a c file, how to do it?
 
Thanks.
标签 (1)
0 项奖励
回复
3 回复数

684 次查看
marvin
Contributor I
Lower 16-bits of the SP you can get by the following code.

volatile unsigned int StackPtr;

asm(move.w SP,StackPtr);
0 项奖励
回复

684 次查看
CrasyCat
Specialist III
Hello
You have to use inline assembly to retrieve value from a register in a C variable.
 
The assembler instructions then depends on the CPU you are targeting.
 
CrasyCat
0 项奖励
回复

684 次查看
Lundin
Senior Contributor IV
Well, it shouldn't be impossible to get the SP through ANSI C:

unsigned char* stackPtr;

{
volatile unsigned char foo;
stackPtr = &foo + sizeof(foo);
}


But I would still recommend inline asm in this case. And to get index registers etc, you must use it.
0 项奖励
回复