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

Ask your beginner questions here.
Post Reply
zer0cat
Posts: 1
Joined: Wed Aug 01, 2018 4:49 am

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

Post by zer0cat » Sat Nov 10, 2018 7:48 pm

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?

sauza
Posts: 1
Joined: Thu Mar 30, 2017 6:18 am

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

Post by sauza » Wed Nov 14, 2018 8:12 am

It is possible by using Heaven’s Gate, take a look at: https://gist.github.com/Cr4sh/76b66b612 ... ll-cpp-L31

User avatar
Vrtule
Posts: 461
Joined: Sat Mar 13, 2010 9:14 pm
Location: Czech Republic
Contact:

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

Post by Vrtule » Wed Nov 14, 2018 12:18 pm

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.

Post Reply