这两天老赵和老包为IL 是不是汇编语言交了火,eaglet 忍不住也想说两句。
首先我们不要拿中文在这里挣,这些词汇其实是从英文翻译过来的,在中文中算外来词。就像.net 中 Property 和 Attribute 都翻译成属性,如果两个人都在讨论属性,但一个说的是Property 一个说的是 Attribute,结果是风马牛不相及,个说个话。
明确了这一点,下面eaglet以英文文献为准来讨论这个问题。
首先看什么叫汇编语言
这是汇编语言的定义,出处 Assembly language (英文维基百科)。
Assembly languages are a family of low-level languages for programming computers . It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture. This representation is usually defined by the hardware manufacturer, and is based on abbreviations (called mnemonics ) that help the programmer remember individual instructions , registers , etc. An assembly language is thus specific to a certain physical or virtual computer architecture (as opposed to most high-level languages , which are usually portable ).
eaglet 简单翻译一下(翻译不一定准确,以英文原文为准,下同)
汇编语言家族包括众多低级计算机编程语言。这些语言实现一种对机器代码或者一些特殊CPU架构的其他常量的符号描述。这些描述通常被硬件厂商定义并且基于 一些帮助程序员记忆的缩写。汇编语言具体到确定的物理或虚拟计算机架构(而不是像大多数高级语言通常可以在不同硬件架构之间移植)
在看看IL的定义,出处 Common Language Infrastructure (英文维基百科)。
Common Intermediate Language (CIL , pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable programming language in the Common Language Infrastructure and in the .NET Framework . Languages which target the .NET Framework compile to CIL, which is assembled into bytecode . CIL is an object-oriented assembly language , and is entirely stack-based . It is executed by a virtual machine .
IL 的全称应该是 Common Intermediate language (通用中间语言,原来被称为MSIL) 是一种存在于CLI 和.net framewok中的低级人工可读的(human-readable) 编程语言。CIL 是一种面向对象的汇编语言,它完全基于堆栈并被虚拟机执行。
从IL 的英文定义来看,它确实是一种汇编语言,而且是面向对象的汇编语言。我们再拿到前面我列出的汇编语言的定义上来对照:
首先它是低级语言,以缩写形式表示编译程序员记忆。但这种语言并不能具体到物理计算机架构,因为它说到底还是一个中间语言,不能直接生成机器代码。但我们 不要忘了汇编语言的定义中还有这么一句 or virtual computer architecture(或者是虚拟计算机架构),虚拟机实际上就是这种虚拟计算机架构,IL 的汇编指令可以被虚拟机直接识别,所以从这种角度来讲IL 还是一种汇编语言。
老赵所说的汇编语言实际上是狭义的汇编语言定义,是那种最低级可以直接被翻译成机器码且和机器码几乎是一一对应的那种汇编语言,比如Z80,8086, 80386这一类的汇编。这些汇编语言知识汇编语言家族中的一类,并不是全部。其实汇编语言家族中还包括一些高级汇编语言,比如宏汇编
看看下面从 assembler 的定义中摘抄的部分段落
More sophisticated high-level assemblers provide language abstractions such as:
- Advanced control structures
- High-level procedure/function declarations and invocations
- High-level abstract data types, including structures/records, unions, classes, and sets
- Sophisticated macro processing
- Object-Oriented features such as encapsulation, polymorphism, inheritance, interfaces
更复杂的高级汇编程序(assembler) 提供语言的如下抽象:
- 高级控制结构
- 高级过程和方法
- 高级抽象数据类型,包括结构/记录,联合,类和集合
- 复杂的宏处理
- 面向对象特性
看 来assember 的定义,我们就不难理解IL 实际上是一种高级面向对象汇编语言,它也是汇编语言家族的一员,所以包建强说IL是汇编语言没有错,老赵说IL不是汇编语言也没错,因为两人根本就不是说 的一个东西。老赵应该说IL 不是那种低级的汇编语言,而包建强应该说IL 是一种高级汇编语言,不过包建强说IL 是汇编语言没有错,因为汇编语言包含高级汇编语言。