English 中文(简体)
What is the difference between assembly code and bytecode?
原标题:

While in the search for the various differences in the meanings of source code, bytecode, assembly code, machine code, compilers, linkers, interpreters, assemblers and all the rest, I only got confused on the difference between bytcode and assembly code.

Particularly the introduction this wikipedia article to describe CIL confused me since it seems to use both terms (assembly code and bytecode) interchangeably making me think they might mean exactly the same.

问题回答

Assembly code normally does mean the human readable form of a machine s native language (the so-called machine language). Byte code on the other hand is normally a language that can be interpreted by a byte code interpreter — so it is not the processor s native language.

Why the confusion then? You can t compare Assembly language versus Byte code this way. Of course a byte code can also have an assembly code — meaning a human readable form of it, because "Assembly language" does not necessary mean that it is for a real machine — but it is a human readable form of some native language — for processors, this native language is the machine code — but you also can have assembly code of a pseudo-(or interpreted) machine like Bytecode.

See also: Assembly Language

Further distress comes of course — like you can see in all the discussion here — because IT people (also myself) tend to be lax in wording. "Assembly language" is often used when speaking about machine code. This of course is not totally correct, because Assembly Language is only the human readable form of some machine s code.

Assembly code normally is used to refer to code that, once compiled to Machine Code, can be executed by a CPU whilst bytecode in a virtual machine.

The source of confusion over CIL might be related to the fact that machine code for CPU X can be interpreted by a Virtual Machine running on CPU Y (for example).

Note that a Virtual Machine implementation can be crafted to interpret any machine code and/or bytecode: it is left to the developers and their aspiration (and time on their hands) ;-)

I remember that since the begining of microcontrollers and microprocessors the word Assembly was used to designate the machine code in a human readable way. It seems to me that Microsoft has caused confusion by using the same word "Assembly" to name what would be the ByteCode produced by their dotNET Framework compilers. So in this case I d say that what "Bytecode" means to the Java runtime is similar to what this new use of the word "Assembly" means for Microsoft dotNET runTime environment. Am I wrong to assume that?

Assembled code is runnable on a CPU with a specific instruction set, while bytecode can be executed in a virtual machine (such as the Java runtime) on any CPU that can run the VM.

assembler is a macro language. It s a set of instructions used to instruct the CPU or other device. It s translated in machine code which are readable instructions by the CPU.

Byte code s are instructions for the virtual machine to be interpreted and still need to get translated into machine code before being executed.

Bytecode is mainly for platform independence and needs a virtual environment to run.

Assembly code is human readable machine code (at a bit upper level) that directly run by the CPU.

Bytecode is not machine/hardware specific (directly handling hardware) but assembly code is machine/hardware specific.





相关问题
How to protect Python source code?

Is it possible to distribute only the bytecode version (.pyc file) of a Python script instead of the original .py file? My app embeds the Python interpreter and calls PyImport_Import to load a script. ...

What optimizations does Python do without the -O flags?

I had always assumed that the Python interpreter did no optimizations without a -O flag, but the following is a bit strange: >>> def foo(): ... print %s % Hello world ... >>>...

Byte code to Java source code

Is it possible to convert a .class file to .java file? How can this be done? What about the correctness of the code extracted from this option?

Generating .class file for JVM

I am working on a project that requires me to generate a java ".class" file on the go that can be later on compiled on the JVM. After learning and working with MSIL (Microsoft IL) which is also a ...

What is the difference between assembly code and bytecode?

While in the search for the various differences in the meanings of source code, bytecode, assembly code, machine code, compilers, linkers, interpreters, assemblers and all the rest, I only got ...

Local variables in java bytecode

I am trying to learn java bytecode and I stumbled on this: I compiled this very simple code with the -g option: public class Test { public static void main(String args[]) { double a = 1.0; int ...

热门标签