内联汇编用gcc [英] inline asm with gcc

查看:168
本文介绍了内联汇编用gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code,它是用ARMASM编制的这一部分:

I have this part of code that was compiling using ARMASM :

/* Software Interrupt */
/* we must save lr in case it is called from SVC mode */
#define ngARMSwi( code)   __asm { SWI code,{},{},{lr} }

例如使用:
ngARMSwi(0x23);

example of use : ngARMSwi( 0x23);

我尝试这个转换使用gcc来编译(code的Sourcery GCC-4.6.2 EABI)。我发现这个链接 http://www.ethernut.de/en/documents /arm-inline-asm.html 但我不能找到一个方法来正确编译此行。

I try to convert this to compile using gcc (code sourcery GCC-4.6.2 eabi). I found this link http://www.ethernut.de/en/documents/arm-inline-asm.html but I cannot find a way to compile this line correctly.

我最好的尝试是

#define ngARMSwi( code)  __asm__ ("SWI " (code) : : :"lr" )

但我得到编译错误:

but I get compile error :

error: expected ':' or ')' before '(' token

任何帮助AP preciated!

Any help is appreciated!

推荐答案

您可能希望

#define ngARMSwi(code) __asm__("SWI %0" : : "I"(code) : "lr")

注意 code 是一个输入指令,如此这般的第三部分。它在instuction地方是由 0%字符串中的标记。在 I 是一种约束 code ,表明它必须是一个8位的常数。

Note that code is an input to the instruction, so it goes in the third section. Its place in the instuction is marked by the %0 in the string. The I is a constraint on code, indicating that it must be an 8-bit constant.

这篇关于内联汇编用gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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