Dayle Probably

Enjoy!

Programs

Here are some programs for the SAP-1 using the original instruction set from Ben Eater.

Multiply

Multiplies x by y and outputs the product. Does not handle overflow. Must reset 13 and 14 between executions.

Source: Ben Eater’s video

LDA 14
SUB 12
JC  6
LDA 13
OUT
HLT
STA 14
LDA 13
ADD 15
STA 13
JMP 0
-
1
product
x
y
00011110
00111100
01110110
00011101
11100000
11110000
01001110
00011101
00101111
01001101
01100000
00000000
00000001
00000000
00000000
00000000

Division

Divides x by y and outputs the quotient. Must reset 13 and 14 between executions. Infinite loop if dividing by 0.

LDA 14
SUB 15
JC  6
LDA 13
OUT
HLT
STA 14
LDA 13
ADD 12
STA 13
JMP 0
-
1
0
x
y
00011110
00111111
01110110
00011101
11100000
11110000
01001110
00011101
00101100
01001101
01100000
00000000
00000001
00000000
00000000
00000000

Fibonacci

Fibonacci sequence algorithm. Loops after it overflows.

LDI 1
STA 14
LDI 0
STA 15
OUT
LDA 14
ADD 15
JC  0
STA 14
OUT
LDA 15
ADD 14
JC  0
JMP 3
x
y
01010001
01001110
01010000
01001111
11100000
00011110
00101111
01110000
01001110
11100000
00011111
00101110
01110000
01100011
00000000
00000000

Add / Subtract loop

A simple program to test conditional jumps. Increments by x until carry, then decrements by x until 0. Repeat.

LDI 0
ADD 15
JC  5
OUT
JMP 1
SUB 15
JZ  1
OUT
JMP 5
-
-
-
-
-
-
x
01010000
00101111
01110101
11100000
01100001
00111111
10000001
11100000
01100101
00000000
00000000
00000000
00000000
00000000
00000000
XXXXXXXX

4 20 69

Simple program that outputs 4 then 20 then 69. Something to keep the kids entertained.

LDI 4
OUT
ADD 14
OUT
ADD 15
OUT
JMP 0
-
-
-
-
-
-
-
16
49
01010100
11100000
00101110
11100000
00101111
11100000
01100000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00010000
00110001