Skip to content

Instantly share code, notes, and snippets.

@Jarvix
Created April 9, 2012 00:38
Show Gist options
  • Save Jarvix/2340557 to your computer and use it in GitHub Desktop.
Save Jarvix/2340557 to your computer and use it in GitHub Desktop.
<label>, <name>, <param> must all match: /[A-Za-z_][A-Za-z0-9_]*/
labels, names and parameters can not have names equal to registers and mnemonics.
LABELS
<label>:
!!! NOT :<label> !!!!
FILE INCLUSION
.include "<relative path>"
.include <{relative path to from base path of library}>
The base address of the latter is defined by the assembler or an assembler flag.
.incbin "<relative path>"
BASE ADDRESS REPLACEMENT
.org <address>
How it works:
the address specified here should be used as a base to all compiler-generated addresses.
so it MUST be added to the addresses of all labels.
MACROS
Definition:
.macro <name>(<params...>)
<code>
.end
params is a comma separated list of unique (for the macro) identifiers
Insert the macro:
.ins <name>(<values...>)
REPETITIONS
.rep <count>
<code>
.end
CONDITIONAL DIRECTIVES
.def <name> [<value>]
Without <value>, value defaults to 1
.if <expr>
.else
.end
<expr> is <const1> = <const2>. Without <const2>, <const2> defaults to 1.
.if 0 => .if 0 = 1 => false
.if 1 => .if 1 = 1 => true
.if HELLO = 5 => depends on HELLO value
.if HELLO => .if HELLO = 1 => depends on HELLO value
both defined names (with .def) and numbers are valid for <const>.
registers and anything else is not.
// 1 when defined, 0 otherwise
isdef(<name>)
example:
.def DEBUG
.def HELLO 0x2000
.if isdef(DEBUG)
Do something
.else
.if isdef(HELLO)
SET PC, HELLO
.end
.end
==== PARSING
case insensitive opcodes and registers
"Str" is a string, either prefixed by the length or appended by 0
'c' is a character, nor prefixed or appended. limited to 1 character. character is taken from ASCII charset.
@TrojaA
Copy link

TrojaA commented Apr 9, 2012

Standard Assembler Preprocessor Directives

LABELS:
Currently Notch's assembler uses : for labels.
It is appropriate to use :.

FILE INCLUSION:
The preprocessor should merge files, for that one need an inclusion command.
It's styled like that: .include "".

BASE ADDRESS REPLACEMENT
Replaces the current address with the given one.
* is the current address and can be altered with simple arithmetic (plus +and minus -)
.org

MACROS
Macros are placed texts by the preprocessor.
Their parameters are seperated by comma ,.

`.macro` <name>([<param> {, <param>}[, ...]])
    <code>
`.end`

To insert a macro one can use `.ins`.

`.ins` <name>([<param> {, <param>}[, ...]])

REPETITIONS
has to be a constant unsigned number.

`.rep` <count>
        <code>
`.end`

CONDITIONAL DIRECTIVES
To defining a constant, one use .def followed by and the .
.def

To undefining a constant one uses `.undef`
`.undef` <name>

<expr> is an expression (<name> = <name> or `isdef`(name)) which can be linked up with conjunctions (`&&` and `||`) .

`.if` <expr>
    <code>
[`.else`
    <code>]
`.end`
(`.else` is optional)

`isdef`(<name>) returns either 1 if the macro is defined or 0 if the macro isn't defined.

example:
.def DEBUG
.def HELLO 0x2000

.if isdef(DEBUG)
        Do something
.else
    .if isdef(HELLO)
        SET PC, HELLO
    .end
.end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment