简体   繁体   English

机器代码和操作码之间有什么区别?

[英]What is the difference between machine code and opcode?

The question is mostly related to PHP because IMHO opcode is mostly mentioned in PHP context. 问题主要与PHP有关,因为IMHO操作码主要在PHP上下文中提到。 According to this description , here's a transformation process of php code into opcode: 根据这个描述 ,这里是一个PHP代码转换为操作码的过程:

php text -> scanning/parsing -> result = tokens -> compiling > result = opcode php text - > scanning / parsing - > result = tokens - > compiling> result = opcode

Several questions here: 这里有几个问题:

1) Is opcode just a portion of machine code, does machine code consist of opcodes? 1)操作码只是机器代码的一部分,机器代码是否由操作码组成? 2) Thinking in the context of Wamp server, what PHP module is responsible for? 2)在Wamp服务器的上下文中思考,PHP模块负责什么? Is that module just PHP interpreter who transforms PHP code into tokens or is it also a compiler who compiles tokens into opcode that is executed on the hardware (processor)? 该模块是PHP解释器,它将PHP代码转换为令牌,还是将令牌编译为在硬件(处理器)上执行的操作码的编译器?

The question is mostly related to PHP because IMHO opcode is mostly mentioned in PHP context. 问题主要与PHP有关,因为IMHO操作码主要在PHP上下文中提到。

In fact Java is more popular for its byte-/opcode 事实上,Java的字节/操作码更受欢迎

1) Is opcode just a portion of machine code, does machine code consist of opcodes? 1)操作码只是机器代码的一部分,机器代码是否由操作码组成?

Yes, but this opcodes are machine-dependent. 是的,但是这个操作码是依赖于机器的。 The interesting thing in Java or PHP bytecode is that it's machine independent and runs in a platform-specific virtual machine. Java或PHP字节码中有趣的事情是它独立于机器并在特定于平台的虚拟机中运行。

2) Thinking in the context of Wamp server, what PHP module is responsible for? 2)在Wamp服务器的上下文中思考,PHP模块负责什么?

No module, it's part of the core. 没有模块,它是核心的一部分。

Lexer => Tokenizer => Compiler

Is that module just PHP interpreter who transforms PHP code into tokens or is it also a compiler who compiles tokens into opcode that is executed on the hardware (processor)? 该模块是PHP解释器,它将PHP代码转换为令牌,还是将令牌编译为在硬件(处理器)上执行的操作码的编译器?

Not exactly. 不完全是。 The resulting bytecode is machine-independent (named "Zend-opcode") and cannot run directly on the hardware. 生成的字节码与机器无关(名为“Zend-opcode”),不能直接在硬件上运行。 The last step is to transform this bytecode into machine-dependent opcodes. 最后一步是将此字节码转换为与机器相关的操作码。

  • Machine code - code which is ready to be executed by machine processor 机器代码 - 准备由机器处理器执行的代码
  • opcode - code to be executed by an interpreter 操作码 - 由解释器执行的代码

Opcode is executed by php core, it's internal feature. 操作码由php核心执行,它是内部功能。 For speeding up php scripts there is a module PHP Accelerator , which caches compiled bytecode so that next time it would be executed by the processor directly 为了加速PHP脚本,有一个模块PHP加速器 ,它缓存编译的字节码,以便下次由处理器直接执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM