t2-5.1  code

t2-code for som 5.1. The instructions are exactly the same as v5, only the encoding is different. To simplify everything only one format (3-arg) is used (instead of two formats).

3-arg   a:16 c:10 op:6, b:32

op is 6 bits. b is 32 bits so it does not need decoding. Some instructions use only 32 bits.

bop dest (c), src1 (a), src2 (b)

c = a op b

ldx  dest (c), idx (a), base (b)
stx  src  (c), idx (a), base (b)
not  dest (c), src (a)

jmp  disp (a)
jt   disp (a), src (c)
jop  disp (a), src1 (c), src2 (b)
efor disp (a), src+ (c), src2 (b)

disp of jump is 16 bits so use (a).

fun  arty (a), fs (c)
ret  src  (a), fs (c)
push src  (a)

Give as large source as possible (16 bits).

call arg1 (c), arg2 (a), ads (b)
case src  (c), lo (a),   hi (b)
sys  num  (c), src1 (a), src2 (b)

mov is an exception, it uses largest dest/src to access large address space and to move values around.

2-arg   d:26 op:6,      b:32

mov  dest (d), src (b)


Note: There are 38 instructions, only 6 bits is necessary, so op code field is 6 bits. That leaves 26 bits to be divided between two arguments.  One argument should be a bit large because it is used as displacement in conditional jump instructions, so it is divided into 16-bit and 10-bit.  This is a bit improvement from v5 which has 8-bit op and leaves only 16+8 bits for arguments. A 8-bit field is too small because even a small immediate can hardly be fitted.  

How a normal call work?

1.  get arity and fs from the target fun
2.  move parameters to param[.] (in vm)
    two param from call instruction and 
    the rest from stack
3.  save reg to new frame (on top of stack)
4.  move param[.] to reg

14 Dec 2010

to reduce the chance of argument not fit into the field, we use the larger field first (as a priority). Therefore "call" use "a" then "c" and "sys" use "b" then "a".

call arg2 (c), arg1 (a), ads (b)
sys  num  (c), src2 (a), src1 (b)

20 Dec 2010
