When I debug a C project, I can see all the assembly codes it compiles into. I want to know what assembly language that it. Is it NASM or MASM or something else? And if I use inline assembly, will I be able to use some other assembly language?
当我调试一个C项目时,我可以看到它编译成的所有汇编代码。我想知道它是什么汇编语言。是NASM还是MASM还是其他什么?如果我使用内联汇编,我是否可以使用其他汇编语言?
3 个解决方案
#1
7
The code it compiles to is not assembly, but straight machine code, at least after link-time optimizations. What you see while debugging is on-the-fly disassembly of the machine code that is currently executing. As such, it has no additional structure, such as labels, macros, etc. such that you would expect to find in high-level assemblers, because this extra information is lost (or, more accurately, never present), when producing machine code.
它编译的代码不是汇编,而是直接的机器代码,至少在链接时优化之后。您在调试时看到的是正在执行的机器代码的即时反汇编。因此,它没有额外的结构,例如标签,宏等,您可能希望在高级汇编程序中找到它,因为在生成机器代码时,这些额外信息会丢失(或者更确切地说,从不存在) 。
If you meant the syntax, Visual Studio shows the assembly directives in Intel syntax, which is different from AT&T syntax, which is a default with GCC and GNU assembler.
如果您指的是语法,Visual Studio将以英特尔语法显示汇编指令,这与AT&T语法不同,后者是GCC和GNU汇编程序的默认语法。
In fact, it may also be gibberish. If you jmp
out of alignment (x86 instructions are variable-length), or to a region that does not contain executable code, but rather data, the disassembler will try to make sense of the data, producing random assembly directives that don't mean anything.
事实上,它也可能是胡言乱语。如果jmp不对齐(x86指令是可变长度的),或者是不包含可执行代码的区域,而是数据,反汇编程序将尝试理解数据,产生随机汇编指令并不意味着任何东西。
This is actually quite common; see for example this image:
这实际上很常见;看这个图像:
add byte ptr [rax], al
is the attempted disassembly of bytes 00 00
, which obviously does not represent actual executable code.
添加字节ptr [rax],al是尝试的字节00 00的反汇编,这显然不代表实际的可执行代码。
#2
2
MSVC can compile binaries for x86, x86_64, ARM and Itanium. So it depends on your target and project settings
MSVC可以编译x86,x86_64,ARM和Itanium的二进制文件。所以这取决于您的目标和项目设置
#3
2
For X86 or X86-X64, Visual Studio includes ML.EXE (MASM 6.00 and later versions were renamed to ML.EXE) for 32 bit code and ML64.EXE for 64 bit code. On a VS project, you can right click on a file name, then properties, ... output files, ... assembly listing ... . The command line option for assembly listing is /Fa. Although called assembly only listing, it produces assembly code.
对于X86或X86-X64,Visual Studio包括用于32位代码的ML.EXE(MASM 6.00及更高版本重命名为ML.EXE)和用于64位代码的ML64.EXE。在VS项目中,您可以右键单击文件名,然后单击属性,...输出文件,...程序集列表....汇编列表的命令行选项是/ Fa。虽然称为仅汇编列表,但它会生成汇编代码。
#1
7
The code it compiles to is not assembly, but straight machine code, at least after link-time optimizations. What you see while debugging is on-the-fly disassembly of the machine code that is currently executing. As such, it has no additional structure, such as labels, macros, etc. such that you would expect to find in high-level assemblers, because this extra information is lost (or, more accurately, never present), when producing machine code.
它编译的代码不是汇编,而是直接的机器代码,至少在链接时优化之后。您在调试时看到的是正在执行的机器代码的即时反汇编。因此,它没有额外的结构,例如标签,宏等,您可能希望在高级汇编程序中找到它,因为在生成机器代码时,这些额外信息会丢失(或者更确切地说,从不存在) 。
If you meant the syntax, Visual Studio shows the assembly directives in Intel syntax, which is different from AT&T syntax, which is a default with GCC and GNU assembler.
如果您指的是语法,Visual Studio将以英特尔语法显示汇编指令,这与AT&T语法不同,后者是GCC和GNU汇编程序的默认语法。
In fact, it may also be gibberish. If you jmp
out of alignment (x86 instructions are variable-length), or to a region that does not contain executable code, but rather data, the disassembler will try to make sense of the data, producing random assembly directives that don't mean anything.
事实上,它也可能是胡言乱语。如果jmp不对齐(x86指令是可变长度的),或者是不包含可执行代码的区域,而是数据,反汇编程序将尝试理解数据,产生随机汇编指令并不意味着任何东西。
This is actually quite common; see for example this image:
这实际上很常见;看这个图像:
add byte ptr [rax], al
is the attempted disassembly of bytes 00 00
, which obviously does not represent actual executable code.
添加字节ptr [rax],al是尝试的字节00 00的反汇编,这显然不代表实际的可执行代码。
#2
2
MSVC can compile binaries for x86, x86_64, ARM and Itanium. So it depends on your target and project settings
MSVC可以编译x86,x86_64,ARM和Itanium的二进制文件。所以这取决于您的目标和项目设置
#3
2
For X86 or X86-X64, Visual Studio includes ML.EXE (MASM 6.00 and later versions were renamed to ML.EXE) for 32 bit code and ML64.EXE for 64 bit code. On a VS project, you can right click on a file name, then properties, ... output files, ... assembly listing ... . The command line option for assembly listing is /Fa. Although called assembly only listing, it produces assembly code.
对于X86或X86-X64,Visual Studio包括用于32位代码的ML.EXE(MASM 6.00及更高版本重命名为ML.EXE)和用于64位代码的ML64.EXE。在VS项目中,您可以右键单击文件名,然后单击属性,...输出文件,...程序集列表....汇编列表的命令行选项是/ Fa。虽然称为仅汇编列表,但它会生成汇编代码。