-
Notifications
You must be signed in to change notification settings - Fork 0
The mod basics
you can copy values from one register to another
all available registers are: REG1 - inf, INP1 - INP584000 and OUT
REG
- register. you can set and get values from it
INP
- input, connected to TimCPU. you can get values from it
OUT
- output. you can set values to it
COPY
command is copies value to register
COPY 9 REG9
- now reg9 is 9
COPY 7 REG5
- now reg5 is 7
another example:
COMM NOW REG20 IS 5 TOO
COPY 5 REG5
COPY REG5 REG20
you can jump and call some marks in your code
MARK
command is used to announce compiler about mark
JUMP
command is used to jump to mark
like this:
JUMP COPY5
...SOME USEFUL CODE...
MARK COPY5
COPY 5 REG5
CALL
command is used to jump to mark and save counter position, what can be restored using RETI
RETI
command is restores counter value
also you can call function like this:
CALL COPY5
...SOME USEFUL CODE...
MARK COPY5
COPY 5 REG5
COMM USE RETI TO RETURN BACK TO CALL
RETI
TEST
command is compare to numbers and jump to mark if condition is true
so we can make cycle what counts from 1 to 10:
COPY 0 REG1
MARK CYCLE
ADDI REG1 1 REG1
TEST REG1 <= 10 CYCLE
COMM REG1 IS COUNTS FROM 1 TO 10 AND GOES HERE
you can use +num instead of mark to set counter to self + num + 1
compiler ignores and don't count as line: MARK
,CONS
,BIND
, COMM
COPY 0 REG1
MARK CYCLE
ADDI REG1 1 REG1
TEST REG1 <= 10 +1
COMM SKIP THIS LINE
COPY 1 REG1
JUMP CYCLE
COMM REG1 IS COUNTS FROM 1 TO 10 AND RESETS TO 1
stack is very powerful thing
PUSH
saves value to stack
POPI
get value from stack to register and delete it
GETI
get value from stack to register
example:
PUSH 1 11
PUSH 1 2
PUSH 1 7
PUSH 1 15
COMM GET 7 TO REG2
GETI 3 REG2
COMM GET 7 TO REG3 AND DELETE IT FROM STACK
POPI 3 REG3
COMM NOW STACK IS [11, 2, 15]
but how to get last element from stack?
STLN
returns stack length
that's how:
PUSH 1 11
PUSH 1 2
PUSH 1 7
PUSH 1 15
PUSH 1 4
PUSH 1 9
COMM SAVE STACK LENGTH TO REG3
STLN REG3
COMM GET LAST VALUE TO REG1
GETI REG3 REG1
you can use constants to save number and use it without rewriting many lines of code
CONS
command saves value to constants array. can be used as value
example:
COMM SET SOME_VALUE TO 10
CONS SOME_VALUE 10
COMM COPY 10 TO REG3
COPY SOME_VALUE REG3
also, you can bind commands using it
binds can store values, registers, inputs, constants and output
BIND
command binds value
example:
COMM NOW SOME_REG IS REG1
BIND SOME_REG REG1
COMM COPY 10 TO REG1
COPY 10 SOME_REG
what if we want to get value from value selected register?
we can make a selector, what contains a lot of tests
...
TEST NUM != 1 +1
COPY REG1 RAX
TEST NUM != 2 +1
COPY REG2 RAX
TEST NUM != 3 +1
COPY REG3 RAX
TEST NUM != 4 +1
COPY REG4 RAX
TEST NUM != 5 +1
COPY REG5 RAX
TEST NUM != 6 +1
COPY REG6 RAX
TEST NUM != 7 +1
COPY REG7 RAX
TEST NUM != 8 +1
COPY REG8 RAX
TEST NUM != 9 +1
COPY REG9 RAX
...
but in version 2.3 or higher, we have better solutions, like RSET and RGET
RSET r/v/c arg1 r/v/c arg2
- set register from register or number arg1 to arg2 value
RGET r/v/c arg1 r arg2
- returns register from register or number arg1 to arg2
and now we can turn this code into this:
RGET NUM RAX
COMM GET REGISTER FROM REGISTER NUM TO RAX
also we can change set function:
RSET RAX NUM
COMM COPY RAX TO REGISTER IN REGISTER NUM