在 Objective C 中调用汇编例程

发布于 2024-07-17 20:05:57 字数 1238 浏览 8 评论 0原文

我在汇编文件 math.nasm 中编写了一个函数 nabs 如下

%ifdef USE_x86_ASM
SECTION .text

    cglobal nABS
;*------------------------*
;* int nABS(int a)        * 
;* return value in eax    * 
;*------------------------*
ALIGN 16
    nABS:
        push ebx
        ......
                ......
                 pop ebx        
        ret
%endif

我从文件 myfunc.c 中的 c 函数 func1 调用此函数
定义了 USE_x86_ASM

我正在使用 nasm 汇编器作为汇编文件 我正在使用 X-code 3.1 版本和 gcc 4.0 编译器 我已在 Xcode 设置 Project Settings/Build/NASM BUILD OPTIONs/OTHER FLAGS AS -DUSE_X86_ASM
中 我还在头文件 myfunc.h 中定义了这个预处理器
我已将 myfunc.h 中的 nABS 声明为

#define USE_x86_ASM 
int nABS(int a);

并将 myfunc.h 包含在 myfunc.c 中
myfunc.c 和 math.nasm 都经过成功编译并生成 math.o 和 myfunc.o,但我收到链接错误

Undefined symbols:
  "_nABS", referenced from:
      _func1 in myFunc.o

有人能告诉我为什么会收到链接错误吗?


我做了建议的修改,另外我删除了 %ifdef 条件,修改后的代码如下

.text
.align 2
.globl _nABS   
.private_extern _nABS  

_nABS: 推送EBX ...... ...... 流行 ebx
雷特 我仍然收到相同的链接错误,但文件已编译但我收到相同的链接错误。 我检查了生成的 .o 是否包含 app.LinkFileList。

I have written a function nabs in assembly file math.nasm
as follows

%ifdef USE_x86_ASM
SECTION .text

    cglobal nABS
;*------------------------*
;* int nABS(int a)        * 
;* return value in eax    * 
;*------------------------*
ALIGN 16
    nABS:
        push ebx
        ......
                ......
                 pop ebx        
        ret
%endif

I am calling this function from c function func1 in file myfunc.c
I am using nasm assembler for assembly file I am using X-code 3.1 version and gcc 4.0 compiler I have defined USE_x86_ASM

in Xcode settings Project Settings/Build/NASM BUILD OPTIONs/OTHER FLAGS AS -DUSE_X86_ASM
Also I have defined this pre-processor in header file myfunc.h also
I have declared nABS in myfunc.h as

#define USE_x86_ASM 
int nABS(int a);

and included myfunc.h in myfunc.c
Both myfunc.c and math.nasm are compiled sussessfuly and generate math.o and myfunc.o, but I get a linking error

Undefined symbols:
  "_nABS", referenced from:
      _func1 in myFunc.o

can anyone tell me why am I getting link error?


I did the modification suggested in addition I removed %ifdef condition the modified code is as follows

.text
.align 2
.globl _nABS   
.private_extern _nABS  

_nABS:
push ebx
......
......
pop ebx
ret
still I am getting same linking error the the file is compiled but I get same linking error.
I checked that the .o generated is included app.LinkFileList.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕烟庭风 2024-07-24 20:05:57

某些 C 编译器会在 C 符号前面添加下划线。 只需将下划线添加到汇编文件中的标签(当然还有 globl 指令)。

Some C compilers add a preceding underscore to C symbols. Just add the underscore to your label in the assembly file (and globl directive, of course).

丶视觉 2024-07-24 20:05:57

迈赫拉德是对的
这应该有效

%ifdef USE_x86_ASM
SECTION .text

;*------------------------*
;* int nABS(int a)        *     
;* return value in eax    *     
;*------------------------*
ALIGN 16
global _nABS
    nABS:
        push ebx
        ......
                ......
                 pop ebx        
        ret
%endif

Mehrad is right
This should work

%ifdef USE_x86_ASM
SECTION .text

;*------------------------*
;* int nABS(int a)        *     
;* return value in eax    *     
;*------------------------*
ALIGN 16
global _nABS
    nABS:
        push ebx
        ......
                ......
                 pop ebx        
        ret
%endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文