在C使用ASM命令 [英] Using ASM command in C

查看:169
本文介绍了在C使用ASM命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在c。使用ASM一个小问题。我想执行指令:

  LDR PC,=为0x123456

这给我的错误,在操​​作意外的标记。

  ASM(LDR PC,=为0x123456);

这给了无效的约束。

  ASM(LDR PC,M(为0x123456));

什么是做到这一点的正确方法?


解决方案

您使用的是这样的:

  ASM(LDR PC,=为0x123456);

这是不是一个标准的ARM汇编指令,但作为一个编译器扩展提供了一个伪指令。当你编译这个伪指令被转换为其它汇编指令。这似乎铿锵不支持此编译器扩展(见本线程)。你应该做的转换装配说明自己,请参阅如何的 LDR伪指令的转变。<​​/ p>

I have a small question about using ASM in c. I want to execute the instruction:

LDR PC,=0x123456

This gives me the error "unexpected token in operand".

asm("LDR PC,=0x123456");

This gives "invalid constraint".

asm("LDR PC," : "m" (0x123456));

What's the right way to do this?

解决方案

You are using this:

asm("LDR PC,=0x123456");

This is not a standard ARM assembly instruction, but a pseudo-instruction provided as a compiler extension. This pseudo-instruction is converted to other assembly instructions when you compile it. It seems clang doesn't support this compiler extension (see this thread). You should do the conversion to assembly instructions yourself, see the ARM documentation for how the LDR pseudo-instruction is converted.

这篇关于在C使用ASM命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆