AR# 46408: 13.4 EDK - How to access registers in SDK C-Code
13.4 EDK - How to access registers in SDK C-Code
Some registers, especially the dedicated ones (e.g. the stack pointer), may be useful to reference within C-code. How can I access them?
One way to do this,is to use assembly. For MicroBlaze, the instruction to access the stack pointer would be:
register int *stack_ptr asm("r1");
This will grab the dedicated register (r1 in MicroBlaze), and put it into a register-int data type. You can now reference the pointer to get the data at the stack address, print the stack address, or other functions.
To print this address, cast the stack_ptr type to a void, like follows:
printf("This is my stack pointer: %p", ( void * )stack_ptr);