0 .. sx microprogram v 1.0   10 July 2006
0 .. include  djnz            3 July 2011
0 ..
0 .s
0 x.ts
0 x.fp
0 x.sp
0 x.nx
0 y.ff
0 y.arg
0 b.tbus
0 b.dbus
0 b.pc
0 d.fp
0 d.ts
0 a.tbus
0 a.pc
0 j.pc1
0 j.pcarg
0 j.tbus
0 alu.add
0 alu.sub
0 alu.inc
0 alu.dec
0 alu.z
0 alu.eq
0 alu.op
0 alu.p1
0 alu.p2
0 .. load registers
0 lir
0 lts
0 lfp
0 lsp
0 lnx
0 lff
0 lpc
0 mR
0 mW
0 .. next micro ads
0 ifT
0 ifF
0 decode
0 trap
0 .m
0 :fetch
0 ..  mR(pc)->ir, dispatch
0   a.pc mR lir decode ;
1 :bop
1 ..  mR(sp)->ff
1 ..  sp-1
1 ..  alu(ts op ff)->ts, pc+1, fetch
1   x.sp alu.p1 a.tbus mR b.dbus lff ;
2   x.sp alu.dec b.tbus lsp ;
3   x.ts y.ff alu.op b.tbus lts j.pc1 lpc /fetch ;
4 :uop
4 ..  alu(ts op ?)->ts, pc+1, fetch
4   x.ts alu.op b.tbus lts j.pc1 lpc /fetch ;
5 :get
5 ..  sp+1
5 ..  ts->mW(sp)		; push ts
5 ..  alu(fp-arg)->tbus, mR(tbus)->ts, pc+1, fetch
5   x.sp alu.inc b.tbus lsp ;
6   d.ts x.sp alu.p1 a.tbus mW ;
7   x.fp y.arg alu.sub a.tbus mR b.dbus lts j.pc1 lpc /fetch ;
8 :put
8 ..  alu(fp-arg)->tbus, ts->mW(tbus)
8 ..  mR(sp)->ts		; pop ts
8 ..  sp-1, pc+1, fetch
8   x.fp y.arg alu.sub a.tbus d.ts mW ;
9 :popts
9   x.sp alu.p1 a.tbus mR b.dbus lts ;
10   x.sp alu.dec b.tbus lsp j.pc1 lpc /fetch ;
11 :ld
11 ..  sp+1
11 ..  ts->mW(sp)		; push ts
11 ..  mR(arg)->ts, pc+1, fetch
11   x.sp alu.inc b.tbus lsp ;
12   d.ts x.sp alu.p1 a.tbus mW ;
13   y.arg alu.p2 a.tbus mR b.dbus lts j.pc1 lpc /fetch ;
14 :st
14 ..  ts->mW(arg)
14 ..  mR(sp)->ts		; pop ts
14 ..  sp-1, pc+1, fetch
14   d.ts y.arg alu.p2 a.tbus mW /popts ;
15 :ldx
15 ..  mR(sp)->ff	 	; pop ads
15 ..  sp-1
15 ..  alu(ff+ts)->tbus, mR(tbus)->ts, pc+1, fetch
15   x.sp alu.p1 a.tbus mR b.dbus lff ;
16   x.sp alu.dec b.tbus lsp ;
17   x.ts y.ff alu.add a.tbus mR b.dbus lts j.pc1 lpc /fetch ;
18 :stx
18 ..  mR(sp)->nx		; pop idx
18 ..  sp-1
18 ..  mR(sp)->ff		; pop ads
18 ..  alu(nx+ff)->tbus, ts->mW(tbus)
18 ..  sp-1
18 ..  mR(sp)->ts		; pop ts
18 ..  sp-1, pc+1, fetch
18   x.sp alu.p1 a.tbus mR b.dbus lnx ;
19   x.sp alu.dec b.tbus lsp ;
20   x.sp alu.p1 a.tbus mR b.dbus lff ;
21   x.nx y.ff alu.add a.tbus d.ts mW ;
22   x.sp alu.dec b.tbus lsp /popts ;
23 :lit
23 ..  sp+1
23 ..  ts->mW(sp)		; push ts
23 ..  arg->ts, pc+1, fetch
23   x.sp alu.inc b.tbus lsp ;
24   d.ts x.sp alu.p1 a.tbus mW ;
25   y.arg alu.p2 b.tbus lts j.pc1 lpc /fetch ;
26 :jmp
26   j.pcarg lpc /fetch ;
27 :jt
27 ..  alu(ts=0), ifTrue j3  ; if true, don't jump
27   x.ts alu.z ifT /j3 ;
28 :j2
28 ..  <jump>
28 ..  pc+arg, mR(sp)->ts	; pop ts
28 ..  sp-1, fetch
28   j.pcarg lpc x.sp alu.p1 a.tbus mR b.dbus lts ;
29   x.sp alu.dec b.tbus lsp /fetch ;
30 :jf
30 ..  alu(ts=0), ifTrue j2 ; if true,  jump
30   x.ts alu.z ifT /j2 ;
31 :j3
31 ..  <don't jump>
31 ..  pc+1, mR(sp)->ts	; pop ts
31 ..  sp-1, fetch
31   j.pc1 lpc x.sp alu.p1 a.tbus mR b.dbus lts ;
32   x.sp alu.dec b.tbus lsp /fetch ;
33 :call
33 .. <call with ret ads on ts>
33 ..  sp+1
33 ..  ts->mW(sp), pc+1		; flush stack
33 ..  pc->ts
33 ..  arg->tbus->nx, mR(tbus)->ir	; fetch fun, nx=ads
33 ..  alu(sp+arg)->tbus, fp->mW(tbus) ; save old fp
33 ..  alu(sp+arg)->fp->sp	; new fp, sp
33 ..  alu(nx+1)->pc, fetch
33   x.sp alu.inc b.tbus lsp ;
34   x.sp alu.p1 a.tbus d.ts mW j.pc1 lpc ;
35   b.pc lts ;
36   y.arg alu.p2 b.tbus lnx a.tbus mR lir ;
37   x.sp y.arg alu.add a.tbus d.fp mW ;
38   x.sp y.arg alu.add b.tbus lfp lsp ;
39   x.nx alu.inc j.tbus lpc /fetch ;
40 :ret
40 .. <ret with retads on TS>
40 .. <retv with retads on frame>
40 ..  sp->ff
40 ..  alu(fp=ff), ifFalse r2	; do retv
40 ..  ts->pc  			; do ret
40 ..  alu(fp-arg)->sp
40 ..  mR(sp)->ts			; pop ts
40 ..  sp-1
40 ..  mR(fp)->fp, fetch		; restore fp
40   x.sp alu.p1 b.tbus lff ;
41   x.fp y.ff alu.eq ifF /r2 ;
42   x.ts alu.p1 j.tbus lpc ;
43   x.fp y.arg alu.sub b.tbus lsp ;
44   x.sp alu.p1 a.tbus mR b.dbus lts ;
45   x.sp alu.dec b.tbus lsp ;
46   x.fp alu.p1 a.tbus mR b.dbus lfp /fetch ;
47 :r2
47 ..  alu(fp+1)->tbus, mR(tbus)->ff ; ret ads
47 ..  ff->pc
47 ..  alu(fp-arg)->sp
47 ..  mR(fp)->fp, fetch
47   x.fp alu.inc a.tbus mR b.dbus lff ;
48   y.ff alu.p2 j.tbus lpc ;
49   x.fp y.arg alu.sub b.tbus lsp ;
50   x.fp alu.p1 a.tbus mR b.dbus lfp /fetch ;
51 :inc
51 ..  ts->nx	; save ts
51 ..  alu(fp-arg)->tbus, mR(tbus)->ts
51 ..  alu(ts+1)->ts
51 ..  alu(fp-arg)->tbus, ts->mW(tbus)
51 ..  nx->ts, pc+1, fetch
51   x.ts alu.p1 b.tbus lnx ;
52   x.fp y.arg alu.sub a.tbus mR b.dbus lts ;
53   x.ts alu.inc b.tbus lts ;
54   x.fp y.arg alu.sub a.tbus d.ts mW ;
55   x.nx alu.p1 b.tbus lts j.pc1 lpc /fetch ;
56 :dec
56 ..  ; similar to inc but alu.dec at line 3
56   x.ts alu.p1 b.tbus lnx ;
57   x.fp y.arg alu.sub a.tbus mR b.dbus lts ;
58   x.ts alu.dec b.tbus lts ;
59   x.fp y.arg alu.sub a.tbus d.ts mW ;
60   x.nx alu.p1 b.tbus lts j.pc1 lpc /fetch ;
61 :djnz
61 ..  alu(ts,dec)->ts
61 ..  alu(ts=0) ifTrue djnz2
61 ..  pc+arg, fetch
61   x.ts alu.dec b.tbus lts ;
62   x.ts alu.z ifT /djnz2 ;
63   j.pcarg lpc /fetch ;
64 :djnz2
64 ..  mR(sp)->ts
64 ..  sp-1, pc+1, fetch
64   x.sp alu.p1 a.tbus mR b.dbus lts ;
65   x.sp alu.dec lsp j.pc1 lpc /fetch ;
66 :sys
66 :array
66 :end
66   trap j.pc1 lpc /fetch ;
67 ..
67 .e
