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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

4,138件の閲覧回数
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 返答(返信)

628件の閲覧回数
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 件の賞賛

628件の閲覧回数
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 件の賞賛

628件の閲覧回数
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 件の賞賛