views:

120

answers:

2

Hello everybody, I've got a question concerning nasm and its linkage to C++. I declare a litte test function as

extern "C" void __cdecl myTest( byte i1, byte i2, int stride, int *width );

and I call it like this:

byte i1 = 1, i2 = 2;
int stride = 3, width = 4;
myTest( i1, i2, stride, &width );

the method only serves to debug assembly and have a look at how the stack pointer is used to get the arguments. beyond that, the pointer arguments value shall be set to 7, to figure out how that works. This is implemented like this:

    global _myTest

_myTest:
    mov     eax, [esp+4]     ; 1
    mov     ebx, [esp+8]     ; 2
    mov     ecx, dword [esp+16]    ; width
    mov     edx, dword [esp+12]    ; stride

    mov eax, dword [esp+16]
    mov dword [eax], 7

    ret

and compiled via

yasm -f win32 -g cv8 -m x86 -o "$(IntDir)\$(InputName).obj" "$(InputPath)"

, then linked to the c++ app. In debug mode, everything works fine. the function is called a couple of times and works as expected, whereas in release mode the function works once, but subsequent programm operations fail. It seems to me that something's wrong with stack/frame pointers, near/far, but I'm quite new to this subject and need a little help. thanks in advance! a.

+1  A: 

Well, it seems that I have to preserve ebx via push/pop.

arionik
A: 

May be this helps: FLAC uses some sources in assembler which intended to be compiled by nasm.

VitalyVal