Conversion of assembly language code into c language

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Conversion of assembly language code into c language

Jump to solution
1,476 Views
FAISAL0323
Contributor II

Hi Experts, 

 I am using MPC5748G where my issue is ; it’s sometimes got stuck some where in code hence making  watchdog to reset the microcontroller.  

To find root cause of above issue, mine objective is to send out certain CAN messages before watchdog reset our microcontroller.

That logic already has been  implemented successfully by enabling watchdog interrupt and its ISR and it’s working normally. 

Now I want to covert below written assembly language instructions into c language instructions and want to send out the content of these registers through CAN in watchdog interrupt ISR.  Please let me know following things.

1 How I can convert these instructions into C language? 

2 How to get access to these registers. What kind of statement I should write so that I can get access to these registers. 

269A0808-1A0B-4C50-9B99-D58318DD3451.jpeg

10E86CC5-C6BA-47D2-B662-11DB860942AE.jpeg

Regards 

0 Kudos
1 Solution
1,446 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

MSR is a core register, it's not memory mapped. The only way to access core registers is to use asm instructions. In C language, you can use macros like this:

#define MFMSR() ({unsigned int rval; __asm__ volatile("mfmsr %0" : "=r" (rval)); rval;})
#define MTMSR(v) __asm__ volatile("mtmsr %0" : : "r"(v))

And then use them in C code:

unsigned int temp;

temp = MFMSR(); //read MSR

MTMSR(temp); //write MSR

If you want to store the content in asm function (like in IVOR handler), you need to get address of C variable and store it to the variable using asm instructions.

Regards,

Lukas

 

 

View solution in original post

0 Kudos
2 Replies
1,447 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

MSR is a core register, it's not memory mapped. The only way to access core registers is to use asm instructions. In C language, you can use macros like this:

#define MFMSR() ({unsigned int rval; __asm__ volatile("mfmsr %0" : "=r" (rval)); rval;})
#define MTMSR(v) __asm__ volatile("mtmsr %0" : : "r"(v))

And then use them in C code:

unsigned int temp;

temp = MFMSR(); //read MSR

MTMSR(temp); //write MSR

If you want to store the content in asm function (like in IVOR handler), you need to get address of C variable and store it to the variable using asm instructions.

Regards,

Lukas

 

 

0 Kudos
1,416 Views
FAISAL0323
Contributor II

Hi Lukas,

Thanks for your response. It has been solved

 

Regards

 

0 Kudos