```baby←{⎕IO ⎕ML←0 1           ⍝ The Manchester Small Scale Experimental Machine.

fetch←{,(yshift ⍵)⌿⍺}                   ⍝ line ⍵ from store ⍺
⍝   store←{⍺⍺@((yshift ⍵⍵)∘⊣)⍵}             ⍝ (with extended @)             <V>@
store←{⍺⍺@(1⍳⍨yshift ⍵⍵)⊢⍵}             ⍝ store-matrix ⍵ with ⍺⍺ in line ⍵⍵

decode←∊∘(+\0 5 8 3)∘⍳∘⍴{(⍺⍺ ⍵)⊂⍵}      ⍝ instruction decode S:0-4 PI:13-15

yshift←(0=⍳≢⍵)∘{                        ⍝ Y-shift: mask from ssem-binary
~1∊⍵:⍺                              ⍝ 0: done
(¯1⌽⍺)∇ dec ⍵                       ⍝ mask shift
}

c←⍺ ⍺⍺ ⍵                            ⍝ carry bits
~1∊c:⍺ ⍵⍵ ⍵                         ⍝ no carry bits: done
(⍺≠⍵)∇ 0,¯1↓c                       ⍝ shift & add/sub carry bits
}

incdec←{(⍵>⍺⍺\⍵)∨⍵⍵\~⍵}                 ⍝ binary successor/predecessor

inc←∧incdec<                            ⍝ binary successor
dec←<incdec∧                            ⍝ binary predecessor
neg←{(⍵<∨\⍵)∨<\⍵}                       ⍝ 2s complement negation

⍺←0∧2↑↓⍵                                ⍝ A and CI initially 0 by default

0{                                      ⍝ CI increment
A CI_ M←⍵                           ⍝ Acc Ctrl-Instr Store-Matrix
S _ PI _←decode M fetch CI          ⍝ decode of next instruction

0 0 0≡PI:0 ∇ A(M fetch S)M          ⍝ jmp: CI ←STORE[S]
1 0 0≡PI:(M fetch S)∇ A CI M        ⍝ jrp: CI+←STORE[S]
0 1 0≡PI:0 ∇(neg M fetch S)CI M     ⍝ ldn: A ←-STORE[S]
1 1 0≡PI:0 ∇ A CI(A store S⊢M)      ⍝ sto: STORE[S]←A
0 0 1≡PI:0 ∇(A sub M fetch S)CI M   ⍝ sub: A-←STORE[S]
1 0 1≡PI:0 ∇(A sub M fetch S)CI M   ⍝ sub:   ..  ..
0 1 1≡PI:({0}\⌽A)∇ A CI M           ⍝ cmp: CI+←A<0
1 1 1≡PI:M                          ⍝ hlt: final memory state
}⍺,⊂⍵                                   ⍝ initial machine state
}
code_colours

test script

Back to: notes

Back to: Workspaces
```