用汇编语言实现的编程语言
最近我偶然发现 JONESFORTH,它是用普通汇编语言实现的 Forth 编程语言的解释器。
我发现这个实现很有趣,因为它展示了如何用汇编语言实现一种语言,尽管我知道实现一种语言可能是一个严重的可移植性权衡。
所以我想知道是否还有其他用汇编语言实现的编程语言,其源代码仍然可用(甚至可能仍在积极开发中)?
Recently I've stumbled upon JONESFORTH, which is an interpreter for the Forth programming language implemented in plain assembly language.
I find this implementation interesting, because it shows how a language can be implemented in assembly language, although I understand that implementing a language can be a serious portability tradeoff.
So I wondered if there are any other programming languages implemented in assembly language, whose source are still available (and maybe are even still under active development)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然可能用汇编语言实现,但对于大多数语言来说,出于多种原因,实际上并不建议这样做:汇编代码非常难以开发和维护,而且它是由定义不可移植。
也就是说,某些语言更容易生成以下实现:
生成 Brainfuck 的汇编实现 >
Forth 在汇编中有许多实现,这就是它在多个非 PC 工作站的固件中使用的原因。您可以在此处找到一些针对各种平台的程序集实现。
许多 BASIC 解释器都是用汇编语言编写的 - 事实上,对于大多数 BASIC 来说可能都是如此70 年代末和 80 年代初的各种家用计算机中的实现。有些可以在此处找到。
While it is possible to write a language implementation in assembly, for most languages it is not really advisable to do so for a variety of reasons: assembly code is notoriously difficult to develop and maintain, and it is by definition not portable.
That said, some languages are significantly easier to produce implementations for:
It is very easy to produce an assembly implementation for Brainfuck
Forth has a number of implementations in assembly, which is why it is used in the firmware of several non-PC workstations. You can find some assembly implementations for various platforms here.
Many BASIC interpretters have been written in assembly - in fact that was probably true for most BASIC implementations in the various home computers of the late '70s and early '80s. Some can be found here.
自 1.0 起 Turbo Pascal 的多个版本 用汇编语言编写。这是当时将编辑器、编译器、调试器和编译后的程序装入 64 KB RAM 的唯一方法,并且它提供了前所未有的编辑-编译-调试速度。
Several versions of Turbo Pascal since 1.0 were written in assembly language. It was the only way to fit an editor, compiler, a debugger, and the compiled program into the 64 KB RAM of the time, and it provided for blazing edit-compile-debug speeds never witnessed before.
Pico Lisp 最近(在过去几年)从 C 语言切换到 x86-64 汇编语言。这是我能想到的唯一在“现代”时代发生的例子。有一些从汇编器引导的较旧的 Lisp 仍在使用。实际上等等,最近有人用ARM汇编器写了一个Scheme(http://armpit.sourceforge.net/index.html)。我不知道他们为什么会做出这么疯狂的事情,而且我也没有仔细研究过。当然用C编写并添加一些asm函数来实现call/cc等是很常见的。
1980 年代的 BDS C 编译器是用 8080 汇编程序编写的,源代码在几年前发布,但它主要具有历史意义。
Pico Lisp recently (in the past few years) switched from C to x86-64 assembler. That's the only example I can think of that was undertaken in the "modern" era. There are some older Lisps bootstrapped from assembler still in use. Actually wait, someone recently wrote a Scheme in ARM assembler (http://armpit.sourceforge.net/index.html). I don't know why they would have done such a crazy-sounding thing and I haven't looked at it closely. Of course it's very common to write in C and add some asm functions to implement call/cc or the like.
The BDS C compiler from the 1980's was written in 8080 assembler and the source code was released a few years ago, but it's mostly of historical interest.
最终,每种语言都是用汇编程序实现的,C 编译器必须以某种方式将 + 映射到汇编程序指令。只有在汇编器内核中语言的一部分有多大以及在语言本身中定义语言的一部分方面存在很大的可变性。
如果你看看 jonesforth,你会发现内核的一部分,甚至在汇编文件中,实际上是 Forth 代码,而不是汇编代码。
所以标准可能是主程序的语言是汇编语言还是语言本身。更重要的可能是一种语言是否需要构建另一种语言,例如 Pascal 中的 lisp 实现、使用 C 实现的 Gforth。依赖于您无法控制的编译器可能是一种责任,并且可能会导致语言标准有些做法已经过时了。要跟上编译器中处理器的新功能,需要深入的汇编知识,无论您的编译器是自行编写还是汇编编写。
只要你有源代码,语言就没有消亡。所以你可以看看Fig-Forth (1980)。 jonesforth 的部分灵感来自于我的 ciforth,一个用于 16/32/64 位的 i86 汇编器 Forth。
我可以特别推荐“yourforth”,这是我专门为教育目的而制作的汇编程序中的 Forth。它有练习,但尚未完成:https://bitbucket.org/avanderhorst/yourforth
Ultimately every language is implemented in assembler, a c-compiler must map + to an assembler instruction, somehow, somewhere. There is only a great variability in how large a part of a language is in the assembler kernel, and how large part of the language is defined in the language itself.
If you look at jonesforth you will see that a part of the kernel, even in the assembler file, is in fact Forth code, not assembler code.
So the criterion may be whether the language of the main program is assembler or the language itself. More important may be whether a languages needs another language to be build, e.g. a lisp implementation in Pascal, Gforth implemented using C. It may be a liability to be dependant from a compiler that you don't control, and language standards that may make some practices obsolescent. Keeping up with new features of a processor in a compiler, requires in depth assembly knowledge, whether your compiler is written in itself or in assembly.
As long as you have the source the language is not dead. So you can look at FIG-Forth's (1980). jonesforth has part of its inspiration from my ciforth, an i86 assembler Forth for 16/32/64 bits.
I can recomment especially `` yourforth '' a Forth in assembler that I made specifically for educational purposes. It has exercises, but those are not completed yet: https://bitbucket.org/avanderhorst/yourforth
虽然不是纯粹用汇编语言,但 vm 和 luajit 的其他一些部分是用宏汇编语言编写的,适用于多个平台(主要是 x86),纯粹是为了它提供的速度(mike paul 可能还有其他原因,但我相信这是主要一)。宏处理器也是定制的,但是使用 lua。
Although not purely in assembly, the vm and some other sections of luajit is written in macro'd assembly, for multiple platforms (mainly x86), purely for the speed it provides (mike paul may have other reasons, but I beleive this is the main one). The macro processor is also custom built as well, using lua however.