Skip to content

Assembler syntax

Robin Hänni edited this page Jun 25, 2017 · 7 revisions

Assembler syntax

Basic syntax

The LALWE assembler is built up from the following schematic:
Mnemonic [<argument1>[ <argument2>[ ...]]]
Each line of code is in itself one single instruction. Every instruction consists of a mnemonic and a variable amount of arguments. Some mnemonics require no arguments, some require one and some require two arguments. The only exception is the function call which requires at least one argument (the function name) and then demands as many additional arguments as the amount of parameters for the function to be called. You may put an arbitrary amount of spaces between the words but you must not put tabs between them. The first word is always expected to be the mnemonic and the order of the arguments (given that a mnemonic requires more than one argument) does always matter. A list of all the instructions can be found here

Identifier syntax

Each argument can be either a number or an identifier. Identifiers must always be defined before they are used (exception: a label may be used before it's defined). An identifier can contain both upper- and lowercase letters, digits and underlines but must not contain any other character nor begin with a number. Furthermore, you are not allowed to use a mnemonic as an identifier

Examples of custom identifiers

variable1 -- valid
VaRiAbLe2 -- valid
var_3 -- valid
v3_4 -- valid
3variable -- invalid
var-4?2&ä -- invalid
add -- invalid

If you use a number as an argument, you can either use a plain number (=absolute) or an offset number (=relative). All you need to do to offset a number, is to wrap it in brackets and then prefix it with a pointer. There are three available pointers:

  • dpt -- the datapointer (for global variables)
  • loc -- the framepointer in reverse mode (for local variables)
  • par -- the framepointer in normal mode (for parameters)

Examples of offset numbers

dpt[237]
loc[2]
par[5]

A list of the register identifiers can be found on the registers page. Last but not least, all identifiers and numbers (absolute or relative) can be prefixed with an asterisk (*). If you do this, you tell the processor that you don't want it to use the address that the identifier/number represents, but the value at that address (in memory) instead.

Comment syntax

You can insert comments into your code by prefixing a line with a number sign (#). Note that you may only insert comments on separate lines. Inserting comments after an instruction on the same line is not supported. The assembler will ignore any line that is prefixed with a number sign.

Macro syntax

The LALWE assembler features a couple of macros, that are necessary to accomplish certain tasks. You can find explanations for each of them on the macros page. the syntax of macros is identical to the basic instruction syntax, with the only difference that the first word is not a mnemonic but the macro.

Clone this wiki locally