Skip to content
jbw3 edited this page Apr 11, 2017 · 12 revisions

Overview

Comments start with an octothorpe (#) and continue to the end of the line.

# This is a comment

There may be no more than one instruction per line. Each instruction starts with its mnemonic and is followed by zero or more arguments. Arguments are separated by commas.

NOP
ADD R0
MOV R0, 7
SUB R0, R1, R2

Arguments may be either register names or immediate values. Immediate values may be constants or integers. Integers may be in binary, octal, decimal, or hexadecimal format.

MOV  R5,  0b101  # binary
MOV  R10, 0o777  # octal
ADDI R0,  42     # decimal
MOV  R2,  0xD2   # hexadecimal

Note than mnemonics, register names, and numbers are case insensitive.

Constants

A constant's name may only be composed of letters, numbers, and underscores. The first character may not be a number. Also, note that constant names are case sensitive. Constants may only be defined once, and no more than one constant may be defined on a line. There are two types of constants: labels and constants set to explicit values.

A label is defined by placing a colon (:) after a constant name. Its value will be the address of the following instruction. If a label is placed on the same line as an instruction, it must precede the instruction.

label1: MOV R1, R2
label2:
    ADD R1, R3

An explicitly defined constant is defined by placing an assignment operator (=) after a constant name. It may be assigned to an expression composed of numeric values, previously defined constants, and the following operators: +, -, *, /, %, ~, &, |, ^, <<, and >>. Parentheses may also be used. Note that constants may not be placed on the same line as an instruction.

x = 2 + 3
y = 0xABC
z = (y << 4) & 0xff

label:
    ADDI R1, x

l = label + 4

The reserved identifier here may be used to refer to the current address.

# get the address of the MOV instruction
addr = here
MOV r0, r1

# infinite loop
JMP here

The reserved identifier start_address may be used to set the start address of the program. start_address may only be defined once and must be defined before any other constants in the file. Also, the start address must be word aligned.

start_address = 0x10000

# This label's value is 0x10000
label:
    MOV R0, R1, R2

Operator Precedence

Operator precedence given in order from highest to lowest precedence:

Operators Description
+ - ~ unary plus, unary minus, and complement
* / % multiplication, division, and modulo
+ - addition and subtraction
<< >> shift left and shift right
& bitwise AND
^ bitwise XOR
| bitwise OR
Clone this wiki locally