Conversion of assembly language code into c language

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Conversion of assembly language code into c language

跳至解决方案
1,625 次查看
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 项奖励
回复
1 解答
1,595 次查看
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 项奖励
回复
2 回复数
1,596 次查看
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 项奖励
回复
1,565 次查看
FAISAL0323
Contributor II

Hi Lukas,

Thanks for your response. It has been solved

 

Regards

 

0 项奖励
回复