本帖最后由 weibo78 于 2019-12-1 20:17 编辑
简单地说,可以用类似下面这种做法:
这个sys.c中的语句,把下面这段
/*__asm void MSR_MSP(uint32_t addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}*/
改成标准的ASM+C格式即可
void MSR_MSP(uint32_t addr)
{
__asm volatile("MSR MSP, r0"); //set Main Stack value
__asm volatile("BX r14");
}
与此相关的ASM写法,arm也给出了一个解释:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0205g/Chdjggff.html
摘录了内容如下,
[size=1.1em]Virtual registers
Inline assembly code for the compiler always specifies virtual registers. The compiler chooses the physical registers to be used for each instruction during code-generation, and enables the compiler to optimize fully the assembly code and surrounding C or C++ code. The pc (r15), lr (r14), and sp (r13) registers cannot be accessed at all. An error message is generated when these registers are accessed. The initial values of virtual registers are undefined. Therefore, you must write to virtual registers before reading them. The compiler warns you if code reads a virtual register before writing to it. The compiler also generates these warnings for legacy code that relies on particular values in physical registers at the beginning of inline assembly code, for example: int add(int i, int j) { int res; __asm { ADD res, r0, r1 // relies on i passed in r0 and j passed in r1 } return res;}This code generates the following warning and error messages:
|