T.I.M | ISA Specification
 All Pages
Assembly

This page lists all information on the ISA assembly code structure, syntax and semantics.

Comments

All comments are single line only. The start of a commone is signified by a semicolon ; and implicitly ended by a newline.

Tokens

This section details how to refer to registers and create labels & immediate/literal values.

These tokens are refered too later in the main assembly language grammar.

Note
The assembly language is case sensitive. If you refer to a token in any case other than the one specified, you will get an error.

Labels

All label declarations are preceded by a single full stop or dot. They may contain alpha-numeric characters, dashes (-) and underscores (_). Labels must start with a letter however.

Labels may be placed on their own line, or immedietly preceding an assembly instruction/opcode. They may not appear after an instruction on the same line. The exception to this is that some instructions (such as JUMPI and JUMPR) allow labels to be immediates/arguments. When used inside an instruction, the preceding dot should be omitted.

Examples

.main
.text
.quick-stort
.quick-sort-aux
.printf_formatted
.array_start_1
.function2

Registers

All Registers are preceded by a $ sign. Special purpose registers are refered to by their memonics detailed in Special Purpose Registers. Hence to refer to the link register, we would use the token $LR. Remember that register memonics are case sensitive.

General Purpose Registers are refered to by the letter R followed by their number. There are 16 general purpose registers numbered 0 to 15.

Temporary Registers are refered to by the letter T followed by their number. There are 8 temporary registers numbered 0 to 7.

Examples

$PC ; Program Counter
$SP ; Stack Pointer
$LR ; Link Register
$R0 ;
$R9 ; General Purpose Registers
$R14 ;
$T6 ; Temporary register six.

Imediates & Literals

Immediates and literals simply refer to all constant values passed as arguments to instructions. Binary, Hexadecimal, Decimal and floating point literals are supported.

  • Binary literals are refered to by prefixing their value with 0b followed by ones and zeros as appropriate.
  • Hex literals are prefixed with 0x followed by a string of hex characters 0..F.
  • Decimal literals are prefixed with 0d followed by decimal digits as needed. This is the default literal type, so if a literal is encountered with no 0? prefix it is assumed to be a decimal.
  • Floating point literals are prefixed with 0f followed by decimal digits and a decimal point where needed.

Not all literal types are valid as arguments to all instructions. Floating point literals for example make no sense as an argment to an integer arithmetic instruction.

Examples

0b01010101 ; Binary literal.
0d50013 ; Eplicitly Decimal literal
0xAB50C ; Hex literal.
0f3.141 ; Floating literal for PI.
40823 ; An unprefixed literal, implicitly assumed to be decimal.
Note
Different instructions will accept literals of different sizes. When the supplied literal cannot be represented in the desired number of bits, the upper bits that do not fit are simply discarded.

Macros and Special Instructions.

There are some assembly instructions that are actually aliases for other instructions in a particular form, or that do not actually represent an operation.

NOP

The NOP instruction stands for no-operation and has no side effects, it simply takes a single instruction cycle to execute. It is an alias for the ANDR instruction with all register operands set to R0.

DATA

The DATA instruction does not actually execute anything. It simply reserves 4 bytes of memory space for its single immediate value. It should be used to load constants into global or heap memory.

Conditional Execution Codes

Any instruction (but not a label) may be preceded by a condtional execution code which defines a predicate that must be satisfied, lest it be treated as a NOP instruction. These codes are defined thus:

Code Predicate
?A Always executed. This is the default.
?T Execute only if the result of the last TEST instruction was TRUE.
?F Execute only if the result of the last TEST instruction was FALSE.
?Z Execute only if the zero flag is set.

If a condition code is omitted from the instruction statement, it is assumed to be ?A and the instruction will always execute by default.


Grammar

NULL ::=
NEWLINE ::= '\r' | '\n' | '\r\n'
BYTE_MASK ::= ('0' | '1') ('0' | '1') ('0' | '1') ('0' | '1')
LABEL_NAME ::= '.' ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '-' | '_')*
LABEL_DECLARATION ::= LABEL_NAME
COMMENT ::= ';' (.*) NEWLINE
SPECIAL_REG ::= '$' ('SP' | 'PC' | 'LR' | 'IR' | 'IS' | 'SR' | 'TR')
GENERAL_REG ::= '$R' ('0'..'9') ('0'..'5')?
TEMP_REG ::= '$T' ('0'..'7')
REGISTER ::= (SPECIAL_REG | GENERAL_REG | TEMP_REG)
IMM_BINARY ::= '0b' ('0' | '1')+
IMM_DECIMAL ::= ('0d')? ('0'..'9')+
IMM_HEX ::= '0h' ('0'..'9' | 'A'..'F')+
IMM_FLOAT ::= '0f' ('0'..'9')+ ('.' ('0'..'9')+)? ('e' ('-')? ('0'..'9')+)?
IMMEDIATE ::= (IMM_BINARY | IMM_HEX | IMM_DECIMAL | IMM_FLOAT)
CONDITION_CODE ::= '?' ('A' | 'T' | 'F' | 'Z')
PROGRAM ::= (LINE NEWLINE)+
LINE ::= COMMENT |
LABEL_DECLARATION ((CONDITION_CODE)? INSTRUCTION)? COMMENT |
NULL
INSTRUCTION ::= I_LOAD |
I_STORE |
I_PUSH |
I_POP |
I_MOV |
I_JUMP |
I_CALL |
I_RETURN |
I_TEST |
I_HALT |
I_AND |
I_NAND |
I_OR |
I_NOR |
I_XOR |
I_LSL |
I_LSR |
I_NOT |
I_IADD |
I_ISUB |
I_IMUL |
I_IDIV |
I_IASR |
I_FADD |
I_FSUB |
I_FMUL |
I_FDIV |
I_FASR |
I_NOP |
I_SLEEP |
I_DATA
I_LOAD ::= 'LOAD' GENERAL_REG GENERAL_REG GENERAL_REG (BYTE_MASK)? |
'LOAD' GENERAL_REG (IMMEDIATE | LABEL)
I_STORE ::= 'STORE' GENERAL_REG GENERAL_REG GENERAL_REG (BYTE_MASK)? |
'STORE' GENERAL_REG (IMMEDIATE | LABEL)
I_PUSH ::= 'PUSH' REGISTER
I_POP ::= 'POP' REGISTER
I_MOV ::= 'MOV' REGISTER REGISTER |
'MOV' REGISTER (LABEL | IMMEDIATE)
I_JUMP ::= 'JUMP' REGISTER |
'JUMP' (IMMEDIATE | LABEL)
I_CALL ::= 'CALL' REGISTER |
'CALL' (IMMEDIATE | LABEL)
I_RETURN ::= 'RETURN'
I_TEST ::= 'TEST' REGISTER REGISTER
I_HALT ::= 'HALT'
I_AND ::= 'AND' REGISTER REGISTER REGISTER |
'AND' REGISTER REGISTER (IMMEDIATE | LABEL)
I_NAND ::= 'NAND' REGISTER REGISTER REGISTER |
'NAND' REGISTER REGISTER (IMMEDIATE | LABEL)
I_OR ::= 'OR' REGISTER REGISTER REGISTER |
'OR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_NOR ::= 'NOR' REGISTER REGISTER REGISTER |
'NOR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_XOR ::= 'XOR' REGISTER REGISTER REGISTER |
'XOR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_LSL ::= 'LSL' REGISTER REGISTER REGISTER |
'LSL' REGISTER REGISTER (IMMEDIATE | LABEL)
I_LSR ::= 'LSR' REGISTER REGISTER REGISTER |
'LSR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_NOT ::= 'NOT' REGISTER REGISTER
I_IADD ::= 'IADD' REGISTER REGISTER REGISTER |
'IADD' REGISTER REGISTER (IMMEDIATE | LABEL)
I_ISUB ::= 'ISUB' REGISTER REGISTER REGISTER |
'ISUB' REGISTER REGISTER (IMMEDIATE | LABEL)
I_IMUL ::= 'IMUL' REGISTER REGISTER REGISTER |
'IMUL' REGISTER REGISTER (IMMEDIATE | LABEL)
I_IDIV ::= 'IDIV' REGISTER REGISTER REGISTER |
'IDIV' REGISTER REGISTER (IMMEDIATE | LABEL)
I_IASR ::= 'IASR' REGISTER REGISTER REGISTER |
'IASR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_FADD ::= 'FADD' REGISTER REGISTER REGISTER |
'FADD' REGISTER REGISTER (IMMEDIATE | LABEL)
I_FSUB ::= 'FSUB' REGISTER REGISTER REGISTER |
'FSUB' REGISTER REGISTER (IMMEDIATE | LABEL)
I_FMUL ::= 'FMUL' REGISTER REGISTER REGISTER |
'FMUL' REGISTER REGISTER (IMMEDIATE | LABEL)
I_FDIV ::= 'FDIV' REGISTER REGISTER REGISTER |
'FDIV' REGISTER REGISTER (IMMEDIATE | LABEL)
I_FASR ::= 'FASR' REGISTER REGISTER REGISTER |
'FASR' REGISTER REGISTER (IMMEDIATE | LABEL)
I_NOP ::= 'NOP'
I_SLEEP ::= 'SLEEP' REGISTER
I_DATA ::= 'DATA' (IMMEDIATE | LABEL)