2.5 KiB
2.5 KiB
Design
Parsing
- First we tokenize the input (syntax check)
- Then we interpret the input (semantics check)
- Then we execute the input
Notation
[operation][number type], e.g.divifor divide (div) integer%[register]for addressing registers$[value]for using literals/immediate values;for end of statement (mandatory)[label]:for labels#[text]for comments: any text is ignored till a newline (\n) is found- Elements must be separated by whitespace character
- Good:
add $2 $5 %A; - Bad:
add $2$5%A;
- Good:
Examples
Divide register A by 5 and store the result in register A:
divi %A $5 %A;
Increment B until it is 10:
# Set B to zero
addi $0 $0 %B;
loop:
addi $1 %B %B;
lti %B $10;
jmp loop;
Reserved symbols
The following whitespace characters are used to separate symbols:
- space (
) - tab (
\t) - return carriage (
\r) - newline (
\n)
The following characters are used as identifiers:
- dollar (
$) for immediate (literal) values - percentage (
%) for register identifiers - colon (
:) for jump labels - semicolon (
;) for statement termination - hash (
#) for comments
All symbols are reserved keywords and can therefore NOT be used as labels.
Symbols
Operands
addiadd the first to the second argument and store the result in the third argumentsubisubtract the first from the second argument and store the result in the third argumentdividivide the first by the second argument and store the result in the third argumentmulimultiply the first by the second argument and store the result in the third argumentshlishift left the first argument by the number of positions given by the second argument and store the result in the third argumentshrishift right the first argument by the number of positions given by the second argument and store the result in the third argumentsetiset the first register argument to the second argumentintcalls the interrupt specified by the first (integer) argument
Control Flow
jmpjump to the label given by the first argumentltiexecute next statement if argument 1 is less than argument 2 else skip the next statementgtiexecute next statement if argument 1 is greater than argument 2 else skip the next statementeqiexecute the next statement if argument 1 is equal to argument 2 else skip the next statement
Interupts
- 0..9 range:
0put value of register A as ASCII character on stdout1put value of register A as decimal integer on stdout