cancel
Showing results for 
Search instead for 
Did you mean: 

access R0-R4 in C

othane
Associate II
Posted on April 28, 2010 at 23:53

access R0-R4 in C

3 REPLIES 3
Posted on May 17, 2011 at 13:49

If you want to exercise this level of control you simply need to write the function in assembler. In C you could cast an address to a function call and also provide it with parameters. This would in effect permit you to define r0-r4, and pc. You could also use assembler inline within your function(s).

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
disirio2
Senior
Posted on May 17, 2011 at 13:49

If you are using GCC it is not difficult nor dangerous, you can enforce a variable into a specific register, you just declare it like this:

register unsigned int n asm(''r2'');

You may also need to declare the variable ''volatile'' or the compiler may optimize out assignments to the variable if it is not explicitly used after the assignment.

GCC is very effective if you need to do inline assembler.

Giovanni

---

ChibiOS/RT http://chibios.sourceforge.net

othane
Associate II
Posted on May 17, 2011 at 13:49

Thanks, I would do this but I cannot grantee we will be using GCC where this code is going to run.

I ended up doing something similar to what clive1 suggested, which is just copy all the 4 parameters into the registers whether they are used by the function or not , which seems to work well enough, eg:

 

typedef void (*internal_task)(uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3);

 

void SYS_Run(void (*task), uint8_t argc, uint32_t argv[])

 

{

 

    internal_task t = (internal_task)task;

 

    t(argv[0], argv[1], argv[2], argv[3]);

 

}