I have a trouble with a compiling assembly code (nasm).
On Linux (elf32) it not fails after compilation using g++, but when I tried to build it with i686-w64-mingw32-g++
On Windows the GCC compiler expects a leading underscore in external symbols. So change all wct
in the asm file to _wct
.
If you want to test the program in Windows and in Linux you can "globalize" two consecutive labels: wct
and _wct
:
...
global wct
global _wct
...
wct:
_wct:
...
Linux gets the wct
without underscore and Windows gets it with it.
BTW: The assembly procedure is a C function and has to follow the CDECL calling convention. The function can freely change the registers EAX
, ECX
, and EDX
(caller saved). The other registers (EBX
,ESI
,EDI
,EBP
) have to be returned unchanged. If the function needs to use them, it has to save and restore them (callee saved):
wct:
_wct:
push esi ; sp+= 4
push edi ; sp+= 4
push ebx ; sp+= 4
; ======
; sp+= 12
mov esi, [esp+16]
mov edi, esi
mov ecx, [esp+20]
...
pop ebx
pop edi
pop esi
ret