Page 1 of 1

How i can use one Asm code to x86 and x64?

Posted: Sat Nov 10, 2018 7:48 pm
by zer0cat
Hello
I have some code in C++, which invokes Asm procedure. One procedure is 32 bit (asm x86), and other is 64 bit (asm x64).
Example:

Code: Select all

x86 proc
mov eax,dword ptr[edx]
ret
x86 proc

x64 proc
mov rax,qword ptr [rdx]
ret
x64 proc
Can I compile the code into a 32-bit PE file that detects the architecture and, depending on the bit depth of Windows, calls x86 or x64 proc? Or it is impossible?

Re: How i can use one Asm code to x86 and x64?

Posted: Wed Nov 14, 2018 8:12 am
by sauza
It is possible by using Heaven’s Gate, take a look at: https://gist.github.com/Cr4sh/76b66b612 ... ll-cpp-L31

Re: How i can use one Asm code to x86 and x64?

Posted: Wed Nov 14, 2018 12:18 pm
by Vrtule
You can write two ASM procedures: one for 32-bit and one for 64-bit platform, and use preprocessor macros (ifdefs) to compile only the procedure appropriate to the selected target.