Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits)

Compiler Update

Today we want to give you some insights how our "compiler" works. In the last devlog, we already introduced the M80 Assembly Language. Today it's about how to convert the written source code into byte code.

Given the sample line:

MOV 8 acc ;Test Comment

Tokenizer: The first step is to split the line into its basic components. In the first place we always expect an instruction and depending on the kind of the instruction no, one or two arguments. This will result in a dictionary/struct like this:

{command: "MOV", args:[8, acc], line:0, opCode: 0}

Beside the instruction and arguments, the line and a placeholder for the opcode are stored to make debugging support easier.

The tokenizer also checks for valid syntax and throws errors when an illegal instruction is found or an invalid address.

In a next step, the compiler takes the tokenized code and translate it in our op codes. For "MOV" there are two variants available. 10xy and 2xxy:

| 10xy | MOV x(R/P) y(R/P) | Copies a value of a register to target register |
| 2xxy | MOV x(V) y(R/P)   | Copies a integer to target register             |

As the first argument is a number (integer), the second pattern is used resulting in: 2080. Where 08 is the hex representation of 8 and 0 is the index for the register acc.

You can have a look at the code here: 

https://github.com/NimbleBeasts/Devtober2020-Game/blob/master/src/_Autoloads/Com...

Original Post:

https://nimblebeastscollective.itch.io/ming-inc/devlog/184587/compiler-update