Compile Assembly Output generated by VC++?

偶尔善良 提交于 2019-12-04 08:58:21

Remove listing.inc Remove security_check_cookie reference add INCLUDELIB MSVCRT ...et Robert est ton oncle!

Also you can add: EXTERN _getchar:PROC and just before ret: call _getchar This will wait for a key press before the program closes.

Honkjonk.

I did this recently. It turns out you can still do this in 32-bit mode in MSVC2012 but I think 64-bit mode is hopeless.

For 32-bit mode here is what you do.

Create an empty project and a source file Source.cpp

 #include <stdio.h>
 int main() {
     printf("hello world\n");
     return 0;
 }
  1. Right lick on your project and select "Build Customization" and
    select masm as described here http://www.masm32.com/board/index.php?topic=9231.0
  2. Under C++/OutputFiles select Assembly Output /FA
  3. Comipile in 32-bit mode Release mode
  4. Load the Source.asm file into MSVC so you can view it. It won't work yet. A few changes are necessary.
  5. Under C++/Optimization turn off Whole Program Optimization (removes /GL). This adds the line INCLUDELIB MSVCRT
  6. In the Linker/Advanced set the last option "Image Has Safe Exception Handlers"to No (/SAFESEH:NO)
  7. Now you should have a Source.asm file which will do the same thing that Source.cpp file did. Copy the Source.cpp from the Release directory to the same directory as Source.cpp (so it's not deleted when you build/clean).
  8. Add Source.asm (as an existing file) to the Source Files and remove Source.cpp from the build.
  9. Rebuild and you should see "Hello World" without having to change any assembly lines by hand.

I have used this for more complicated functions. I usually do it on a separate module and use extern "C" on the function name to remove the C++ name mangling.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!