I have two files in my CodeBlocks project, main.c, functioninA.s. main.c contains a declaration of an assembly function functioninA.s with extern keyword, a function which I am trying to call from assembly sprintfkeys() with extern keyword as well, and other stuff. functioninA.s contains:
.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
When I run the code, I get this error on call sprintfkeys
line:
D:\folder\newf\Vernam Again\galoislfsrina.s|28|undefined reference to `sprintfkeys'|
||error: ld returned 1 exit status|
So, is this a legit way to call a function? If it is, how do I get this assembly function know that it exists in main.c? I thought, .extern sprintfkeys
would be enough.