目标代码、机器代码和汇编代码之间有什么区别?

你能举例说明它们的不同吗?


当前回答

机器代码是可以由CPU直接执行的二进制(1和0)代码。如果你在文本编辑器中打开一个机器码文件,你会看到垃圾,包括不可打印的字符(不,不是那些不可打印的字符;))。

目标代码是尚未链接到完整程序的机器代码的一部分。它是组成完整产品的特定库或模块的机器代码。它还可能包含在已完成程序的机器代码中没有的占位符或偏移量。链接器将使用这些占位符和偏移量将所有内容连接在一起。

Assembly code is plain-text and (somewhat) human read-able source code that mostly has a direct 1:1 analog with machine instructions. This is accomplished using mnemonics for the actual instructions, registers, or other resources. Examples include JMP and MULT for the CPU's jump and multiplication instructions. Unlike machine code, the CPU does not understand assembly code. You convert assembly code to machine code with the use of an assembler or a compiler, though we usually think of compilers in association with high-level programming language that are abstracted further from the CPU instructions.


Building a complete program involves writing source code for the program in either assembly or a higher level language like C++. The source code is assembled (for assembly code) or compiled (for higher level languages) to object code, and individual modules are linked together to become the machine code for the final program. In the case of very simple programs the linking step may not be needed. In other cases, such as with an IDE (integrated development environment) the linker and compiler may be invoked together. In other cases, a complicated make script or solution file may be used to tell the environment how to build the final application.

也有不同的解释语言。解释型语言依赖于特殊解释器程序的机器码。在基本级别上,解释器解析源代码,并立即将命令转换为新的机器代码并执行它们。现代解释器现在要复杂得多:一次计算源代码的整个部分,在可能的地方缓存和优化,以及处理复杂的内存管理任务。

One final type of program involves the use of a runtime-environment or virtual machine. In this situation, a program is first pre-compiled to a lower-level intermediate language or byte code. The byte code is then loaded by the virtual machine, which just-in-time compiles it to native code. The advantage here is the virtual machine can take advantage of optimizations available at the time the program runs and for that specific environment. A compiler belongs to the developer, and therefore must produce relatively generic (less-optimized) machine code that could run in many places. The runtime environment or virtual machine, however, is located on the end user's computer and therefore can take advantage of all the features provided by that system.

其他回答

源代码,汇编代码,机器代码,对象代码,字节代码,可执行文件和库文件。

对于大多数人来说,所有这些术语都非常令人困惑,因为他们认为它们是相互排斥的。请参见图表了解它们之间的关系。下面给出了每个术语的描述。



源代码

人类可读(编程)语言的指令


高级代码

用高级(编程)语言编写的指令 例如,C、c++和Java程序


汇编代码

用汇编语言(一种低级编程语言)编写的指令。 作为编译过程的第一步,高级代码转换为这种形式。它是汇编代码,然后被转换成实际的机器代码。在大多数系统上,这两个步骤作为编译过程的一部分自动执行。 例如,program.asm


目标代码

编译过程的产物。它可以是机器代码或字节代码的形式。 例如,file.o


机器代码

机器语言指令。 例如,a.o ut


字节码

一种中间形式的指令,可由解释器(如JVM)执行。 例如,Java类文件


可执行文件

链接过程的产物。它们是可以被CPU直接执行的机器码。 例如,一个。exe文件。

注意,在某些情况下,包含字节码或脚本语言指令的文件也可能被认为是可执行的。


库文件

有些代码出于不同的原因被编译成这种形式,比如可重用性,然后被可执行文件使用。

还有一点没有提到,那就是有几种不同类型的汇编代码。在最基本的形式中,指令中使用的所有数字都必须指定为常量。例如:

$1902: BD 37 14 : LDA $1437,X
$1905: 85 03    : STA $03
$1907: 85 09    : STA $09
$1909: CA       : DEX
$190A: 10       : BPL $1902

The above bit of code, if stored at address $1900 in an Atari 2600 cartridge, will display a number of lines in different colors fetched from a table which starts at address $1437. On some tools, typing in an address, along with the rightmost part of the line above, would store to memory the values shown in the middle column, and start the next line with the following address. Typing code in that form was much more convenient than typing in hex, but one had to know the precise addresses of everything.

大多数汇编程序允许使用符号地址。上面的代码应该是这样写的:

rainbow_lp:
  lda ColorTbl,x
  sta WSYNC
  sta COLUBK
  dex
  bpl rainbow_lp

汇编程序将自动调整LDA指令,以便它引用映射到标签ColorTbl的任何地址。使用这种类型的汇编器,编写和编辑代码要比手工输入和维护所有地址容易得多。

机器代码是可以由CPU直接执行的二进制(1和0)代码。如果你在文本编辑器中打开一个机器码文件,你会看到垃圾,包括不可打印的字符(不,不是那些不可打印的字符;))。

目标代码是尚未链接到完整程序的机器代码的一部分。它是组成完整产品的特定库或模块的机器代码。它还可能包含在已完成程序的机器代码中没有的占位符或偏移量。链接器将使用这些占位符和偏移量将所有内容连接在一起。

Assembly code is plain-text and (somewhat) human read-able source code that mostly has a direct 1:1 analog with machine instructions. This is accomplished using mnemonics for the actual instructions, registers, or other resources. Examples include JMP and MULT for the CPU's jump and multiplication instructions. Unlike machine code, the CPU does not understand assembly code. You convert assembly code to machine code with the use of an assembler or a compiler, though we usually think of compilers in association with high-level programming language that are abstracted further from the CPU instructions.


Building a complete program involves writing source code for the program in either assembly or a higher level language like C++. The source code is assembled (for assembly code) or compiled (for higher level languages) to object code, and individual modules are linked together to become the machine code for the final program. In the case of very simple programs the linking step may not be needed. In other cases, such as with an IDE (integrated development environment) the linker and compiler may be invoked together. In other cases, a complicated make script or solution file may be used to tell the environment how to build the final application.

也有不同的解释语言。解释型语言依赖于特殊解释器程序的机器码。在基本级别上,解释器解析源代码,并立即将命令转换为新的机器代码并执行它们。现代解释器现在要复杂得多:一次计算源代码的整个部分,在可能的地方缓存和优化,以及处理复杂的内存管理任务。

One final type of program involves the use of a runtime-environment or virtual machine. In this situation, a program is first pre-compiled to a lower-level intermediate language or byte code. The byte code is then loaded by the virtual machine, which just-in-time compiles it to native code. The advantage here is the virtual machine can take advantage of optimizations available at the time the program runs and for that specific environment. A compiler belongs to the developer, and therefore must produce relatively generic (less-optimized) machine code that could run in many places. The runtime environment or virtual machine, however, is located on the end user's computer and therefore can take advantage of all the features provided by that system.

程序的源文件被编译成目标文件,然后链接器将这些目标文件链接在一起,生成一个包含您的体系结构的机器代码的可执行文件。

当目标文件和可执行文件被文本编辑器打开时,都以可打印和不可打印字符的形式涉及到体系结构的机器代码。

尽管如此,文件之间的二分法是,目标文件可能包含未解析的外部引用(例如printf)。因此,它可能需要链接到其他对象文件。也就是说,需要解析未解析的外部引用,以便通过与其他目标文件(如C/ c++运行时库)的链接来获得良好的可运行的可执行文件。

8b5d32是机器代码

Mov ebx, [ebp+32h]为组装体

lmylib。所以包含8b5d32是目标代码