Storing GPR value to a C variable in MPC5777C

cancel
Showing results for 
Search instead for 
Did you mean: 

Storing GPR value to a C variable in MPC5777C

278 Views
parth_rastogi10
Contributor III

Hi NXP, 

AS I am working in MPC5777C controller, so I need to store a GPR1 value in to a C variable. I am doing this using Inline assembly functions....but I didn't get how to do so. 

So can you please guide me that how can I store any GPR value into a C variable using Inline Assembly code only...coz I need to do so in a C project.

Hoping for your quick response.

Thanks & Regards,

Parth Rastogi

Parth Rastogi
3 Replies

182 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Hi, question is what you like to achieve.

If you want to have certain variable located in the GPR register, then you can simply register storage class.

Otherwise following code are being used for load of variable to the r31 register (where address points to the variable):

asm (lis r30, (address)@h);
asm (ori r30, r30, (address)@l);
asm (lwz r31, 0x0(r30));

Similar sequence for store operation:

asm (lis r30, (address)@h);
asm (ori r30, r30, (address)@l);

asm (stw r31, 0(r30));

182 Views
parth_rastogi10
Contributor III

Can u explain if suppose I am having one C variable "Var" 

I want to store the value stored in R1 register into this local C variable "Var", how can I achieve this using Inline Assembly Code.

I just want to use GPR R1 and simply store its value to local C variable "Var" so that I can use this value in my C code further.

Parth Rastogi
0 Kudos

182 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

I am attaching header file I am using in several my example code for access to/from SPR register or MSR. You may see in comment example of usage. With small modification you can use for GPR access as shown in the first answer.

0 Kudos