1

我试图一起编译程序集和 C 代码(不是 C 到程序集),但无法完成。

例如

文件 common.h

#ifndef __COMMON_H__
#define __COMMON_H__

struct tree{
        tree* left;
        tree* right;

        void* elem;
};

void foo(int c);
#endif

文件common.S

#include "common.h"

    .text
    .globl foo
    .ent foo
foo:
     //foo implementation

    .end foo

当我尝试编译这个时:

# gcc -c common.S
common.h: Assembler messages:
common.h:5: Error: unrecognized opcode `struct tree{'
common.h:7: Error: unrecognized opcode `tree* left'
common.h:8: Error: unrecognized opcode `tree* right'
common.h:10: Error: unrecognized opcode `void* elem'
common.h:12: Error: junk at end of line, first unrecognized character is `}'
common.h:14: Error: unrecognized opcode `void foo(int c)'

有什么方法可以使用 gcc 将 C 定义放入汇编中?

提前致谢。

4

3 回答 3

2

不,您不能在汇编语言中包含 C 声明。汇编器不知道是什么struct tree意思。

如果你想编写一个foo使用你的定义的汇编语言函数struct tree,你将不得不在不使用 C 头文件的情况下完成它。

要了解这可能是什么样子,请用fooC 语言编写函数,对其进行编译gcc -S以生成程序集列表,然后查看生成的编译器生成的common.s文件。(您可能应该在单独的目录中执行此操作,以免破坏现有common.s文件。)

您可能不会看到struct tree对成员名称leftrightelem;的任何引用。相反,您会看到在特定偏移处引用数据的汇编操作码。

于 2011-11-24T04:18:01.907 回答
1

您不需要编译头文件。尝试这个:

# gcc -c common.S

没有

#include <common.h> 

共同点.S

于 2011-11-24T02:14:48.413 回答
0

我建议您查看Inline Assembler Cookbook

于 2011-11-25T04:08:58.880 回答