Skip to content
Permalink
7afb70bdca
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
42 lines (34 sloc) 1.33 KB
- 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?