开发者

Assembly code mixed in with my C++ code. How to port to 64 bit

I am porting 32 bit C++ code into 64 bit in VS2008. The old code has mixed code written in assembly.

Example:

__asm

{
  mov esi, pbSrc
  mov edi, pbDest

  ...

}

I have read somewhere that I need to remove开发者_Go百科 all assembly code and put them all in a separate project and somehow link to it. Can somebody give me the step x step procedure to do this. I know C++ & C# but don't know assembly language. Thanks in advance.


Visual C++ 2005, 2008, or 2010 don't support assembly inlining when compiling for 64-bit platforms. x64 ASM just has way too many intricacies and complexities that can screw up the C(++) code around the __asm block so they just don't allow it. In short, there's no way to "port" it.

I suggest using 64-bit intrinsics with #define and #ifdef when trying to cross-architecture compile such low-level code. Check out: http://msdn.microsoft.com/en-us/library/h2k70f3s.aspx

Edit: If you really know what you're doing, however, you can save the proper ASM bytecodes in some sort of a buffer array and execute that "raw" - via a void* pointer and VirtualProtect() or something similar. Of course, you need to understand x64 calling/returning conventions since you'd essentially be calling a function. Note that this is 99.9% of the time a bad idea.


If you can't use intrinsic functions to perform your tasks, or cannot write the equivalent in C/c++, you're going to have to dive into x64 assembly language. From a high level:

1) Assuming that you're starting with x86 assembly language routines, you'll need to port them to x64.

2) Use ML64 (Microsoft x64 assembler) or an equivalent assembler to assemble your routines into .OBJs that you can link into your C/C++ project.

3) Set up a custom build step that invokes the assembler on your .ASM files.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜