在GCC内联汇编标签 [英] Labels in GCC inline assembly

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

问题描述

在我与海湾合作委员会内联汇编正在进行的实验,我碰到的关于标签的一个新的问题和内联code。

In my ongoing experimentation with GCC inline assembly, I've run into a new problem regarding labels and inlined code.

考虑以下简单的跳转:

__asm__
(
    "jmp out;"
    "out:;"
    :
    :
);

这什么都不做,除了跳转到退出标签。由于是,这code编译罚款。但是,如果你把它放在一个函数里面,然后用优化标志编译,编译器会抱怨:错误:符号'去'已定义

This does nothing except jump to the out label. As is, this code compiles fine. But if you place it inside a function, and then compile with optimization flags, the compiler complains: "Error: symbol 'out' is already defined".

什么似乎是发生的是,编译器重复这种组装code每次内联函数的时间。这将导致标签退出来得到复制,从而导致多个退出标签。

What seems to be happening is that the compiler is repeating this assembly code every time it inlines the function. This causes the label out to get duplicated, leading to multiple out labels.

那么,我该如何解决此问题?难道真的无法内联汇编使用标签?这<一个href=\"http://www.linux-tutorial.info/modules.php?name=Howto&pagename=Assembly-HOWTO/gcc.html\">tutorial在GCC内联汇编提到:

So, how do I work around this? Is it really not possible to use labels in inline assembly? This tutorial on GCC inline assembly mentions that:

因此​​,你可以让把你的汇编
  进入CPP宏和联C
  功能,使任何人都可以使用它作为
  任何C函数/宏。内联函数
  像宏非常多,但
  有时清洁剂来使用。要注意的是
  在所有这些情况下,code会
  重复的,所以只有本地标签(适用的
  1:样式)应该在定义
  ASM code。

Thus, you can make put your assembly into CPP macros, and inline C functions, so anyone can use it in as any C function/macro. Inline functions resemble macros very much, but are sometimes cleaner to use. Beware that in all those cases, code will be duplicated, so only local labels (of 1: style) should be defined in that asm code.

我试图找到这些局部标号的更多信息,但似乎无法找到与内联汇编什么。它看起来像教程是说一个局部标签是一个数字,后面跟一个冒号,(如 1 ),所以我试图用这样的标签。有趣的是,code编译,但是在运行时它只是引发了段错误。嗯......

I tried to find more information about these "local labels", but can't seem to find anything relating to inline assembly. It looks like the tutorial is saying that a local label is a number followed by a colon, (like 1:), so I tried using a label like that. Interestingly, the code compiled, but at run time it simply triggered a Segmentation Fault. Hmm...

所以任何建议,提示,答案...?

So any suggestions, hints, answers...?

推荐答案

一个的声明的的确是一个数字,后跟一个冒号。但是的参考的一个局部标签需要的后缀˚F B ,视无论你想向前或向后看看 - 即 1F 指的是一个 1 标签中的向前方向

A declaration of a local label is indeed a number followed by a colon. But a reference to a local label needs a suffix of f or b, depending on whether you want to look forwards or backwards - i.e. 1f refers to the next 1: label in the forwards direction.

于是宣布标签为 1 是正确的;但要引用它,你需要说 JMP 1F (因为你是在跳这种情况下,前锋)。

So declaring the label as 1: is correct; but to reference it, you need to say jmp 1f (because you are jumping forwards in this case).

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

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