s-code ; no argument 1 add next + top 2 sub next - top 3 mul ... 4 div 5 and 6 or 7 xor 8 not ! top 9 eq next == top 10 ne ... 11 lt 12 le 13 ge 14 gt 15 shl next << top 16 shr next >> top 17 mod next % top 18 ldx M[next+top] 19 stx M[bot+next] = top 22 array alloc(top) 23 end stop execution ; one argument 24 get x SS[fp-x] 25 put x SS[fp-x] = top 26 ld x M[x] 27 st x M[x] = top 28 jmp x pc += x 29 jt x if top != FALSE pc += x 30 jf x if top == FALSE pc += x 31 lit x x 32 call x create new context pc = x 34 inc x SS[fp-x]++ 35 dec x SS[fp-x]-- 36 sys x system function x 38 fun x function header 40 ret x delete context code segment one word = arg:24 op:8 arg 24-bit sign extended op 1..40 stack segment M[] hi top <- stack pointer (sp) next bot ... lo context hi ... current stack ret ads fp' <- frame pointer (fp) lv1 <- SS[fp-1] lv2 ... lo action of call v = get (frame size - arity) SS[fp+v] = fp save old fp fp = sp + v new fp sp = fp + 1 new stack SS[sp] = pc + 1 save return ads pc = x + 1 goto fun body action of ret pc = SS[fp+1] restore pc if( sp > fp+1 ) there is a value to return a = top sp = fp - x + 1 old stack fp = SS[fp] old fp SS[sp] = a return value else sp = fp - x + 1 old stack fp = SS[fp] system call 1 print top as int 2 print top as char 3 getchar() object code file format (op arg)* 0 example of program in s-code fac n if n == 0 ret 1 else return n * fac(n-1) 1 call 17 2 end 3 fun 1 4 get 1 5 lit 0 6 eq 7 jf 3 8 lit 1 9 ret 2 10 get 1 11 get 1 12 lit 1 13 sub 14 call 3 15 mul 16 ret 2 17 fun 0 18 lit 6 19 call 3 20 sys 1 21 ret 1 s-object 32 17 23 0 38 1 24 1 31 0 9 0 30 3 31 1 40 2 24 1 24 1 31 1 2 0 32 3 3 0 40 2 38 0 31 6 32 3 36 1 40 1 0