从程序集x86 32位调用c函数时未定义的引用

时间:2018-05-05 05:50:45

标签: c assembly x86

我的CodeBlocks项目中有两个文件,main.c,functioninA.s。 main.c包含一个带有extern关键字的汇编函数functioninA.s的声明,我试图从汇编sprintfkeys()调用extern关键字,以及其他东西。 functioninA.s包含:

.global _galoislfsrina
.extern sprintfkeys

_galoislfsrina:
pushl %ebp
movl %esp, %ebp

movl 8(%ebp), %ebx   # GET seedIN
movl %ebx, %esi      # make a copy of seedIN
movl 12(%ebp), %ecx  # GET charCount
movl 16(%ebp), %edx  # GET &key[0]
movl $0, %edi

pushl %ebx # save caller-saved registers
pushl %esi
pushl %edi

loop:
    andl $1, %ebx  # generate LSB (output)
    shrl $1, %esi  # apply shift (LFSR_STATE)
    cmpl $0, %ebx  # compare LSB : 0
    jle noMask     # jump if LSB is 1
    xorl $0xA3000000, %esi # apply taps
    noMask:
    incl %edi          # period++

    pushl %edx         # pass keyPtr as arg1
    pushl %esi         # pass LFSR_STATE as arg2
    call sprintfkeys   # sprintfkeys(keyPtr, LFSR_STATE)
    popl %edx          # clean up the stack
    popl %esi          # ...

    addl %eax, %edx # keyPtr += sprintfKeys(keyPtr, LFSR_STATE)
    movl %edi, %ebx # ...
    shll $4, %ebx   # 4*period
    cmpl %ecx, %ebx # compare 4*period : charCount
    jge end         # break if 4*period >= charCount
    cmpl %esi, 16(%ebp) # compare startingState : LFSR_STATE
    jne loop
end:
popl %ebx # save caller-saved registers
popl %esi
popl %edi
movl $1, %eax # return 1
movl %ebp, %esp
popl %ebp
ret

当我运行代码时,我在call sprintfkeys行上收到此错误:

D:\folder\newf\Vernam Again\galoislfsrina.s|28|undefined reference to `sprintfkeys'|
||error: ld returned 1 exit status|

那么,这是一种调用函数的合法方式吗?如果是,如何让这个汇编函数知道它存在于main.c中?我想,.extern sprintfkeys就够了。

0 个答案:

没有答案