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

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

问题描述

我有这部分代码是使用 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(代码源 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" )

但是我得到编译错误:

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

感谢任何帮助!

推荐答案

你可能想要

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

注意 code 是指令的输入,所以它在第三部分.它在指令中的位置由字符串中的 %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天全站免登陆