SX microprogram
notation
transfer
source to dest : src->dest
alu operation to dest
: alu(src1 op src2)->dest
memory read to
dest : mR(ads)->dest
memory write from src
: src->mW(ads)
short hand
sp+1
= alu(sp+1)->sp
sp-1 =
alu(sp-1)->sp
pc+1 = pc+1->pc
pc+arg = pc+arg->pc
alu
op =
{add,sub,mul,div,band,bor,bxor,not,
eq,ne,lt,le,ge,gt,shl,shr,mod,inc,dec}
Microprogram
fetch:
mR(pc)->ir, decode
bop:
mR(sp)->ff
sp-1
alu(ts op ff)->ts,
pc+1, fetch
uop:
alu(ts op ?)->ts, pc+1,
fetch
get:
sp+1
ts->mW(sp)
; push ts
alu(fp-arg)->tbus,
mR(tbus)->ts, pc+1, fetch
put:
alu(fp-arg)->tbus,
ts->mW(tbus)
mR(sp)->ts
; pop ts
sp-1, pc+1, fetch
ld:
sp+1
ts->mW(sp)
; push ts
mR(arg)->ts, pc+1, fetch
st:
ts->mW(arg)
mR(sp)->ts
; pop ts
sp-1, pc+1, fetch
ldx: {ads idx}
mR(sp)->ff
; pop ads
sp-1
alu(ff+ts)->tbus,
mR(tbus)->ts, pc+1, fetch
stx: {ads idx val}
mR(sp)->nx
; pop idx
sp-1
mR(sp)->ff
; pop ads
alu(nx+ff)->tbus,
ts->mW(tbus)
sp-1
mR(sp)->ts
; pop ts
sp-1, pc+1, fetch
lit:
sp+1
ts->mW(sp)
; push ts
arg->ts, pc+1, fetch
jmp:
pc+arg, fetch
jt:
alu(ts=0), ifTrue j3
j2: ; jump
pc+arg,
mR(sp)->ts ; pop ts
sp-1, fetch
j3: ; not jump
pc+1,
mR(sp)->ts ; pop ts
sp-1, fetch
jf:
alu(ts=0), ifTrue j2
pc+1,
mR(sp)->ts ; pop ts
sp-1, fetch
call:
; store ret ads both in ts
and frame
sp+1
ts->mW(sp), pc+1
; push ts
pc->ts
;
ret ads
arg->nx
;
save call ads
mR(arg)->ir
; get fun.fs
alu(fp+arg)->tbus,
fp->mW(tbus) ; save old fp
alu(fp+arg)->fp->sp
; new fp,sp
ts->mW(sp+1)
; save ret ads
alu(nx+1)->pc, fetch
; jump to body
call:
; store ret ads on ts only
sp+1
ts->mW(sp), pc+1
; push ts
pc->ts
;
ret ads
arg->nx
;
save call ads
mR(arg)->ir
; get fun.fs
alu(fp+arg)->tbus,
fp->mW(tbus) ; save old fp
alu(fp+arg)->fp->sp
; new fp,sp
alu(nx+1)->pc, fetch
; jump to body
ret:
; ret with retads on ts
; retv with retads in frame
sp->ff
alu(fp=ff), ifFalse r2
ts->pc
; do ret
alu(fp-arg)->sp
mR(sp)->ts
; pop ts
sp-1
mR(fp)->fp,
fetch ; restore fp
r2:
; do retv
alu(fp+1)->tbus,
mR(tbus)->pc ; ret ads
alu(fp-arg)->sp
mR(fp)->fp, fetch
ret:
; return ads is in frame
alu(fp+1)->tbus,
mR(tbus)->pc ; restore ret ads
sp->ff
alu(fp=ff), ifFalse r2
; do retv
alu(fp-arg)->sp ;
restore sp
mR(sp)->ts
; pop ts
sp-1
mR(fp)->fp,
fetch ; restore fp
r2:
alu(fp-arg)->sp
mR(fp)->fp, fetch
inc:
dec:
sys:
case:
array:
end:
trap fetch
End
8 July 2006