Tasm Introduction
tasm is an intermediate representation (IR) for the tile programming language.
It runs on a stack-based virtual machine called tvm.
Completely written in good, old C programming language.
Best way to learn
We always think that the best way to learn is examples.
Label shadowing
Here we have two labels declared with the same name "myLabel".
But one is globally when the other is inside a proc. So, there is no conflict!
The code below is only written to show label shadowing support of tasm. (It doesn't do really a thing)
jmp _start
proc myProcedure
myLabel:
jmp myLabel
ret
endp ; end of the proc
_start:
myLabel:
push 3.1415926 ; pi number
decf
call myProcedure
jnz myLabel
hlt
check out the instruction list for more info.
Recursive and loop-based factorial
And yes tasm supports recursion!
jmp main ; jump to the entry point
proc getFactorial
jz final
jnz recursion
final: ; top element is zero
inc
jmp end
recursion:
dup
dec
call getFactorial
mult
ret
jmp end
end:
ret
endp
main: ; actually there is no spesific entry point.
push 5
call getFactorial
hlt
Here is the same proc (you can think that as a low level function) with a simple loop.
jmp _start
; factorial func with a loop
proc fact
push 0b1 ; just to show it supports binary literals
swap 0x1 ; and just to show it supports hex literals
loop:
dup
dec
dup
swap 0x2
mult
swap 0x1
jz exit
dec
swap 0x2
mult
swap 0x1
jnz loop
exit:
add
jz exit
ret
endp
_start:
push 5
call fact
hlt
And yes, we support decimal, hexadecimal, binary and floating point numbers.
check out the instruction list.