Live data from Hacker News

Creating a language using only assembly language

speakerdeck.com

31–40 of 67 posts

Re: Creating a language using only assembly language

#31
post #27

Earlier quoted context omitted.

> one of the fun things about it was that I kept the ability to intersperse assembler instructions everywhere - they were treated as normal statements. And the M68k registers were first class variables in the language that could occur in any expression. That sounds like so much horror and so much fun at the same time.

BBC Micro Basic let you interpose assembler in the middle of the program - although it was a two-pass assembler and you had to call both passes seperately with a small FOR loop if you wanted labels to work.

I remember that! I wrote a short assembler program on a BBC to control a milling machine.

Re: Creating a language using only assembly language

#32
I recently needed to make a cross platform assembler for a niche 8-bit micro that only has DOS tooling. After cloning it in a small bit of Python I was looking for a simple way to extend it with macros. It turns out that m4 works really well as an asm macro language and I now have advanced facilities like a code generating expression evaluator and high level control flow statements without any significant change to the core assembler. It blows the doors off what contemporary assemblers (nasm, masm, tasm) can do and hearkens back to the high point of high level assemblers when they peaked in the 70s.

Re: Creating a language using only assembly language

#33
I love seeing this because it matches my recommendation for redoing the stack post-Snowden. I gave two options: (a) Wirth-style [1] with assembler -> high-level assembler -> Modula-2-like language -> safe Oberon-like language -> 4GL-like batteries included language; (b) VLISP-like [2] setup with assembler -> high-level assembler -> LISP interpreter -> PreScheme compiler -> integrated PreScheme/LISP/assembler system -> AOT or JIT compiler for full LISP.

This is kind of like a mix between the two. I like how the author illustrates each step well. The best illustration is showing how easily the core language can transform into a mainstream-grade language with extensible syntax and macro's. A strength worth copying in any new language albeit with guidelines on proper use. I bet it was all pretty fun, too.

[1] http://www.cfbsoftware.com/modula2/Lilith.pdf

[2] http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=E0F...

Re: Creating a language using only assembly language

#34
post #11

Step 1: Make a language high-level enough to build a parser without being a masochist. Step 2: Make a lisp. Step 3: Do it all in lisp. Step 4: Profit. Even Amber( https://github.com/nineties/amber ) and its syntax looks a lot like lisp concept of grammar. But instead of (s expressions) you've got what is very similar to M[expressions] ( https://en.wikipedia.org/wiki/M-expression ). It's amazing what you can with Lisp…

Yeah, it's kind of a cheat. A real language built in assembler would be headaches and I bet a HLL prototype would be hidden somewhere. HLA might be doable, though, especially if macro's are used diligently for pre-optimization work.

Competition has gone down from the 70's and 80's, though. I remember reading a Scheme paper that builds a software interpreter then implements the thing in hardware too. There were also people doing HLL-to-microcode compilers to cheat extra performance out of their chips. These days most projects stop at assembler. I'd love to see people whip out their FPGA's and start trying to outdo 70's-80's era innovation in hardware/software designs maybe for modern languages.

One of my concepts collecting dust is the Secure Python Target that merges a capability machine, LISP-like hardware at core for native bytecodes, and compiler from Python to that language. Result could be quite productive, reliable, and secure. Another was a Secure Haskell (or ML/Ocaml) Target. I don't know that kind of stuff as well, though. Python has enough documentation, community, and simplicity (to a degree) that academics could port some of its core to hardware.

Re: Creating a language using only assembly language

#36

Ok. I'll toot my own horn. In ~1983 I wrote the first iteration of Sensible Solutions for O'Hanlon Computer Systems using MASM. Of course, it had to run in less than 64k. Basically, it was a VM that would run pseudo code. And, the compiler was written in ASM also. In 1985 I wrote TAS, again using MASM. Again, a VM. The language it compiled (in both cases) was written to create business accounting applications, which…

I used to do some assembly on 68000, 6502 and some Z80. It's nice to have those simpler CPUs and the simpler hardware to learn an assembly language on.

I did 6502 in high school from a book and later did 6809 (EE class) and 8088 in college. The funny part was our compiler target for the CSci Compiler Course was an IBM 370 on which they taught the required assembler course. Of that group I liked the 6809 best. The 370 was ok and it sure had a lot more registers. We didn't write our compilers in assembly, but instead used the department's chosen language: Modula-2. It was very odd translating from the dragon book to Modula-2.

Re: Creating a language using only assembly language

#37
post #7

Earlier quoted context omitted.

Is it this project? http://matt.might.net/articles/implementing-a-programming-la...

Nope, I remember numbered evaluators like lc-0 lc-1. Thanks anyway.

Possibly this: https://github.com/zlizta/LC?

Re: Creating a language using only assembly language

#38
post #11

Step 1: Make a language high-level enough to build a parser without being a masochist. Step 2: Make a lisp. Step 3: Do it all in lisp. Step 4: Profit. Even Amber( https://github.com/nineties/amber ) and its syntax looks a lot like lisp concept of grammar. But instead of (s expressions) you've got what is very similar to M[expressions] ( https://en.wikipedia.org/wiki/M-expression ). It's amazing what you can with Lisp…

Yeah, it's kind of a cheat. A real language built in assembler would be headaches and I bet a HLL prototype would be hidden somewhere. HLA might be doable, though, especially if macro's are used diligently for pre-optimization work. Competition has gone down from the 70's and 80's, though. I remember reading a Scheme paper that builds a software interpreter then implements the thing in hardware too. There were also p…

"A real language built in assembler would be headaches"

Depending on what you consider a "real language", it's not that bad. I did a Forth in 80x86 assembler years ago, and it was reasonably easy and fun.

(I did use the BIOS routines for keyboard/screen I/O...they were one character at a time, IIRC).

Re: Creating a language using only assembly language

#39

Earlier quoted context omitted.

Parsing LISP in assembly isn't even so hard. Without a lot of syntactic symbols, you're just finding whitespace and parens. Even syntactic sugar like ' for quote and , or @ in macros are pretty simple to parse compared to C or -- code gods forbid -- C++. What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess.

> What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess. You don't have to write the final Lisp in assembly; you write the first Lisp in assembly, and the final Lisp in Lisp.

Sure. At a naive (but workable) level, you could just use assembly to link all the free space up into one humongoid list at startup, then operate on that using Lisp (either directly, or by having a later stage in the startup transform this rudimentary free list into something more sophisticated).

Re: Creating a language using only assembly language

#40

Earlier quoted context omitted.

Yeah, it's kind of a cheat. A real language built in assembler would be headaches and I bet a HLL prototype would be hidden somewhere. HLA might be doable, though, especially if macro's are used diligently for pre-optimization work. Competition has gone down from the 70's and 80's, though. I remember reading a Scheme paper that builds a software interpreter then implements the thing in hardware too. There were also p…

"A real language built in assembler would be headaches" Depending on what you consider a "real language", it's not that bad. I did a Forth in 80x86 assembler years ago, and it was reasonably easy and fun. (I did use the BIOS routines for keyboard/screen I/O...they were one character at a time, IIRC).

It does depend on the definition. I'd disqualify Forth as a real language, too. I've always considered it a cross-platform, macro assembler for an abstract, machine design. Like P-code was but more flexible. It's definitely interesting and useful but doesn't feel like a 3GL or even a full LISP. I'd see it as a bootstrap (firmware) or compilation target (eg BootSafe) of a high-level language.

Cool that you assembled one, though. (pun intended)

Post reply on HN