Skip to content
Permalink
Browse files
Added collected old material. Needs editing
  • Loading branch information
digehode committed Sep 15, 2021
1 parent c6a040e commit 7afb70bdca974ed924a087296e999061984f8bf0
Show file tree
Hide file tree
Showing 4 changed files with 743 additions and 0 deletions.

Large diffs are not rendered by default.

@@ -0,0 +1,67 @@
21, -1, -2,
19, 20, -1,
18, 0, -2,
17, 17, 0,
0, 0, 0,
0, 0, 0,
-1, 1, 178,
102, 108, 97,
103, 58, 102,
102, 50, 100,
52, 54, 102,
102, 100, 101,
32, 47, 32,
102, 108, 97,
103, 58, 54,
48, 57, 57,
57, 53, 100,
53, 50, 101,
32, 47, 32,
102, 108, 97,
103, 58, 53,
50, 50, 101,
56, 48, 97,
56, 49, 50,
32, 47, 32,
102, 108, 97,
103, 58, 50,
98, 57, 50,
53, 55, 53,
55, 51, 50,
32, 47, 32,
102, 108, 97,
103, 58, 55,
52, 57, 56,
54, 102, 101,
101, 56, 99,
32, 47, 32,
102, 108, 97,
103, 58, 57,
98, 51, 54,
53, 54, 99,
97, 51, 100,
32, 47, 32,
102, 108, 97,
103, 58, 49,
99, 97, 98,
56, 57, 49,
48, 97, 56,
32, 47, 32,
102, 108, 97,
103, 58, 51,
97, 53, 49,
56, 97, 98,
101, 50, 51,
32, 47, 32,
102, 108, 97,
103, 58, 99,
48, 99, 49,
97, 101, 57,
55, 54, 52,
32, 47, 32,
102, 108, 97,
103, 58, 56,
54, 57, 48,
57, 55, 53,
101, 53, 98,
10, 0
@@ -0,0 +1,42 @@
- Single instruction computer.
- Instruction: subtract and branch if less-than-or-equal-to 0. SUBLEQ
- Example: subleq a b c
- Subtract value in memory address a from value in memory address b
- store result in memory address b
- if the value is less than or equal to 0, jump to c
- Programs are made of groups of 3 values (a, b, c)
- Code and data share the same memory
- A jump to -1 terminates
- A jump to -2 just moves forward to the next
group of 3 (essentially means "no jump", just continue)
- Writing to address -1 outputs an ascii value

Example:

If we have a piece of subleq code: 9 10 3 11 9 0 12 12 0 14 100 -1 0

It would be executed like this:


9 10 3, 11 9 0, 12 12 0, 14 100 -1, 0
execute at 0
9 10 3, 11 9 0, 12 12 0, 14 86 -1, 0
execute at 3 (not jumping, just moving on)
9 10 3, 11 9 0, 12 12 0, 15 86 -1, 0
execute at 6 (not jumping, just moving on)
9 10 3, 11 9 0, 12 12 0, 15 86 -1, 0
execute at 0 (jumped!)
9 10 3, 11 9 0, 12 12 0, 15 71 -1, 0
execute at 3 (not jumping, just moving on)
9 10 3, 11 9 0, 12 12 0, 16 71 -1, 0
execute at 6 (not jumping, just moving on)
9 10 3, 11 9 0, 12 12 0, 16 71 -1, 0
execute at 0 (jumped!)
9 10 3, 11 9 0, 12 12 0, 16 55 -1, 0
...and so on


I made an attempt at an interpreter in subleq.py

Maybe if I could complete it, I could run the code in flags.sub... I
wonder what it contains?
@@ -0,0 +1,23 @@
prog = [ 21, -1, -2, #0
19, 20, -1, #3
18, 0, -2, #6
17, 17, 0, #9
0, 0, 0, #12
0, 0, 0, #15
-1, 1, 13, #18
72, 101, 108, #21
108, 111, 32, #24
87, 111, 114, #27
108, 100, 33, #30
10] #33

pc=0 #Program counter. The pointer to where we are

out="" #Somewhere to collect the output to display at the end
while True:
#Load the next 3 values into a, b, c
a,b,c=prog[pc:pc+3]

#now what?

print out

0 comments on commit 7afb70b

Please sign in to comment.