Design considerations for assembly-language syntax

The assembly-language syntax you design this week will ultimately be the syntax that is emitted by your Universal Forward Translator. When you are debugging your translator, you will be reading a lot of assembly code. Take the time to design a concrete syntax that you will find easy to read. I urge you to design a syntax that looks a lot like C++, Python, Go, JavaScript, Pascal, or any other procedural language with infix operators. Such a syntax will make it obvious to anyone what the assembly code is doing, and if you want to implement peephole optimization in module 12, it will give you a head start.

Design considerations

Hear are some specifics for you to keep in mind:

Design for use in the system

A single VM instruction has multiple concrete representations: assembly language, virtual object code, and the SVM’s unparsing template in instructions.c. That instruction also has internal representations inside the UFT. Here are some of the functions involved:

  1. Parse into an assembly-language AST (you write next week)
  2. Unparse back to assembly language (you write this week)
  3. Assemble into an object-code AST (you write next week)
  4. Unparse into object code on disk (I’ve written)
  5. Parse and load into SVM as binary code in memory (you wrote in module 2)
  6. Unparse binary code using the printasm function in file disasm.c, using the unparsing templates in instruction.c (you wrote in module 2)

Here’s how the compositions are used:

The better these compositions preserve the original concrete syntax, the easier your system will be to debug.

Traditional assembly-language syntax is obsolete

Traditional assembly languages are very old, and some of them were constrained by available hardware and software resources. In such cases it was helpful to have very simple syntax. But today’s assembler no longer has to be written in its own assembly language and then assembled by hand. So design a syntax you’ll enjoy reading, and have fun with your design!

If you want an example, check out the syntax I designed for the Universal Machine in COMP 40. Bear in mind that our target is simpler, so our assembly language can be simpler: