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

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


当前回答

8b5d32是机器代码

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

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

其他回答

这里讨论程序集代码。

汇编语言是一种用于计算机编程的低级语言。它实现了数字机器代码和编程特定CPU架构所需的其他常量的符号表示。”

这里讨论机器代码。

机器代码或机器语言是由计算机中央处理单元直接执行的指令和数据系统。

基本上,汇编代码是一种语言,它由汇编程序(类似于编译器)翻译成目标代码(CPU运行的本机代码)。

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

$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的任何地址。使用这种类型的汇编器,编写和编辑代码要比手工输入和维护所有地址容易得多。

其他答案很好地描述了差异,但你也要求视觉。下面的图表显示了它们从C代码到可执行文件的过程。

机器代码是可以由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.

我认为这些是主要的区别

代码的可读性 控制代码在做什么

可读性可以使代码在创建6个月后得到改进或替换,另一方面,如果性能至关重要,您可能希望使用低级语言来针对生产中的特定硬件,从而获得更快的执行速度。

在我看来,今天的计算机已经足够快,可以让程序员通过OOP快速执行。