【发布时间】:2010-10-22 23:27:23
【问题描述】:
我有一组汇编函数,我想通过创建一个头文件在 C 程序中使用它。例如,如果我有定义实际汇编例程的 asm_functions.s 和具有函数原型的 asm_functions.h 以及我需要的一些标准#define。我的目标是使用 C 程序,比如 test_asm.c 来调用汇编函数。
asm__functions.h:
#define ASM_CONST_1 0x80
#define ASM_CONST_2 0xaf
uint8_t asm_foo( int, int, int );
asm__functions.s:
/* dont need this: #include "asm_functions.h" */
.section .text
.type asm_foo, @function
asm__foo:
/* asm code with proper stack manipulation for C calling conventions */
ret
test__asm.c:
#include "asm_foo.h"
int main() {
uint8_t res = asm_foo( 1, 2, 3);
return 0;
}
在这种情况下,编译链接程序的正确方法是什么?我正在尝试这样的事情:
gas -o asm_foo.o asm_foo.s
gcc -o test_asm test_asm.c
但我仍然收到来自 GCC 的链接器错误,说我的汇编例程未定义。我希望这个人为的例子足以解释这种情况。
谢谢!
编辑:
这是我使用单个命令编译时的输出 sn-p:
tja@tja-desktop:~/RIT/SP2/latest$ gcc -o test_pci pci_config.s test_pci.c
/tmp/ccY0SmMN.o: In function _pci_bios_read_byte':
(.text+0x8): undefined reference toPCI_FUNCTION_ID'
/tmp/ccY0SmMN.o: In function _pci_bios_read_byte':
(.text+0xa): undefined reference toREAD_CONFIG_BYTE'
/tmp/ccY0SmMN.o: In function _pci_bios_read_byte':
(.text+0x18): undefined reference toPCI_BIOS_FUNCTION_INT'
/tmp/ccY0SmMN.o: In function _pci_bios_read_byte':
(.text+0x1b): undefined reference toBAD_REGISTER_NUMBER'
/tmp/ccY0SmMN.o: In function _pci_bios_read_word':
(.text+0x30): undefined reference toPCI_FUNCTION_ID'
...
所有这些,例如 PCI_FUNCTION_ID,都在我的头文件中定义,该头文件包含在 C 程序中。当我自己编译汇编代码时没有错误。
【问题讨论】:
标签: assembly linker x86 compilation