Defining an Assembly Language Syntax

A bytecode assembly language program defines globals as well as a sequence of functions and instructions:

 
.globals «number-of-global-variable-slots»
 
«function-definitions»
 
.def main: args=0, locals=«num-locals-or-registers»: ; begin exec here
 
 
halt

For each function, we define the name, how many parameters it has, and how much local space it needs:

 
.def «function-name»: args=«num-args», locals=«num-locals-or-registers»
 
 
ret

Execution begins in function main or at code address 0 if you don’t specify one. The instructions themselves have a bytecode and up to three parameters:

op operand1, operand2, …, operandn

Rather than hard-coding the instruction names (like ret and store), the implementation ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.