T-code Instruction set 

arithmetic/logic 

binary:
add sub mul div mod 
and or xor shl shr
eq ne lt le gt ge 

unary:
not

immediate:
addi subi muli divi modi 
andi ori xori shli shri
eqi nei lti lei gti gei
 
control transfer

call callt ret jmp efor jt jf

data

mov movi movd pass passi ldx stx
lit ads

special

fun sys 

meaning

argument v1..v255 where v1..v63 locals, v64..v255 globals.  In immediate mode, argument is a small integer 0..255.  Locals and globals are accessed to M[v].

add a1 a2 a3	a1 = a2 + a3
addi a1 a2 n	a1 = a2 + n	n unsigned 8-bit 0..255
...
mov a1 a2	a1 = a2
movi a1 n	a1 = n     	n 16-bit 
movd a1 a2 	a1 = M[a2]	ld/st indirect (defer)
ldx a1 a2 a3   	a1 = M[a2+a3]	index
stx a1 a2 a3 	M[a2+a3] = a1

jmp d		pc = d		d 24-bit
jt a d		if a != 0 pc += d	d 16-bit
jf a d		if a == 0 pc += d
efor a d		a++, if a <= adj(a) pc += d
call d		call
callt d		tail call, use old AR
callf d                   forward call similar to call but fun ref is in sym tab
case a d		case a in jmp table, else pc += d
		follows by range lit lo, lit hi, jmp table
fun arity nlocal	function header, arity, nlocal 8-bit 
ret a nlocal	return, nlocal size of AR, a is return value
		nlocal 8-bit
pass a1 a2	M[fp+a1] = a2 
passi a1  n	M[fp+a1] = n	n 16-bit
lit n		v64 = n		n 24-bit
ads n		v64 = n		n 24-bit
sys a1 a2 sysnum	syscall sysnum with a1, a2 opt. input arg.

encoding

0 add sub mul div mod and or xor 
8 eq ne lt le gt ge shl shr 
16 addi subi muli divi modi andi ori xori 
24 eqi nei lti lei gti gei shli shri
32 not mov movi movd pass passi lit ads
40 ldx stx call callt fun ret efor case
48 jmp jt jf sys end callf

note:  "array" is not an opcode anymore, it becomes "sys sysarray a" where a is the register storing the size of allocation.

23 December 2005

argument of syscall 
sysnum: a3 , like imm mode
input at most two:  a1, a2
output v64  if there is output, like func call

syscall number:
1 print          in: a1
2 printc	      in: a1 
3 getchar      in:-    out:v64
4 -
5 fopen	      in: a1, a2   // fp, mode
6 fclose         in: a1        // fp
7 fprint         in: a1, a2   // fp, n
8 fprintc       in: a1, a2   // fp, c
9 fgetc         in: a1  out:v64    //  fp
10 array       in: a1  out:v64
11 load        in: a1

25 December 2005


