查看代码背后的程序集

查看代码背后的程序集

本文介绍了如何使用 Visual C++ 查看代码背后的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读另一个有关两行代码效率的问题,OP 说他查看了代码背后的程序集,并且两行代码在程序集中是相同的.题外话,如何查看编译程序时生成的汇编代码.

I was reading another question pertaining the efficiency of two lines of code, and the OP said that he looked at the assembly behind the code and both lines were identical in assembly. Digression aside, how could I view the assembly code created when a program is compiled.

我使用的是 Microsoft 的 Visual C++,但我也想知道是否可以查看用 Visual Basic 编写的代码背后的程序集.

I'm using Microsoft's Visual C++, but I would also like to know if it's possible to view the assembly behind code written in Visual Basic.

那么,如何查看用 C++ 和 Visual Basic 等高级语言编写的程序背后的汇编代码?

So, how do I view the assembly code behind a program written in higher level languages like C++ and Visual Basic?

推荐答案

有几种方法:

  1. 您通常可以在 Visual Studio(以及 Eclipse)中调试 C++ 时看到汇编代码.为此,在 Visual Studio 中在有问题的代码上放置一个断点,当调试器点击它时,右击并找到转到程序集"(或按 CTRL+ALT+D)

  1. You can normally see assembly code while debugging C++ in visual studio (and eclipse too). For this in Visual Studio put a breakpoint on code in question and when debugger hits it rigth click and find "Go To Assembly" ( or press CTRL+ALT+D )

第二种方法是在编译时生成程序集列表.为此,请转到项目设置 -> C/C++ -> 输出文件 -> ASM 列表位置并填写文件名.同时选择Assembly Output"到Assembly With Source Code".

Second approach is to generate assembly listings while compiling. For this go to project settings -> C/C++ -> Output Files -> ASM List Location and fill in file name. Also select "Assembly Output" to "Assembly With Source Code".

编译程序并使用任何第三方调试器.为此,您可以使用 OllyDbg 或 WinDbg.您也可以使用 IDA(交互式反汇编程序).但这是最核心的做法.

Compile the program and use any third-party debugger. You can use OllyDbg or WinDbg for this. Also you can use IDA (interactive disassembler). But this is hardcore way of doing it.

这篇关于如何使用 Visual C++ 查看代码背后的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:26