Calling a masm function from cpp

1.7k Views Asked by At

I am working on a project where I want to implement some function using assembly, both 32 and 64 bit, my setup is Visual Studio 2015 community and using MSVC. I am trying to call a function implemented in assembly from my cpp code.

My assembly file and function looks like this:

IFDEF RAX
ELSE
.model flat, stdcall
ENDIF


.code

PUBLIC CheckParity

; bool CheckParity(size_t Result)
    CheckParity PROC

    IFDEF RAX

    mov     rax, 0
    add     rcx, 0
    jnp     jmp_over
    mov     rax, 1

    ELSE

    mov     eax, 0
    pop     ecx
    add     ecx, 0
    jnp     jmp_over
    mov     eax, 1

    ENDIF

jmp_over:
    ret
CheckParity ENDP

END

Declaration in header:

extern "C" bool CheckParity(size_t Result);

Calling the function:

CheckParity(SomeValue);

The error I get when compiling the project:

Error   LNK2019 unresolved external symbol _CheckParity referenced in function "public: virtual long __thiscall Emulation::_ASE_EMULATION_INSTANCE_FILE::ExecuteInstruction(struct Memory::_ASE_MEMORY_ACCESS *,unsigned char *,unsigned int)" (?ExecuteInstruction@_ASE_EMULATION_INSTANCE_FILE@Emulation@@UAEJPAU_ASE_MEMORY_ACCESS@Memory@@PAEI@Z)   ase C:\Users\Alien\documents\visual studio 2015\Projects\xed2_test\ase\ASEEmulation.obj 1   

The weird thing here is that this compiles and links with no errors for 64 bit. The problem only arises when linking for 32 bit.

I have read and tried the following posts with no luck:

Calling a library made in MASM to C or C++

Calling An Asm Function From C

0

There are 0 best solutions below