This copy machine program prints the solution to a well-known puzzle. Explanation of the syntax will follow.
- What solution will be printed for which well-known puzzle?
EXECUTION CODE .--> LoopA-1: (LoopB-4:) 'LoopA-1' --> ExecutionLocation ; halt/hang | |.--> LoopA: (LoopB-3:) Decremented --> DecrementMe | LoopA+1: Decremented --> NegativeDoubleMe | LoopA+2: '-1' --> IncrementMe | |.--> LoopB through LoopB+8: no-op ; 9 no-ops |.--> LoopB+9: @ RemainderBy48 --> PrintMe | | LoopB+10: NegativeDoubled --> NegativeDoubleMe | LoopB+11: AddedLoopBPlus11 --> Subtract4TimesFromMe | LoopB+12: Subtract4TimesMe --> IncrementMe `---- LoopB+13: Subtracted4Times --> ExecutionLocation ; loop back
VARIABLES, MOSTLY AUTOMATIC (initial values given, final values in comments)
ExecutionLocation: LoopA ; ..., LoopB+13, LoopA-1: execution begins
; at LoopA and halts (hangs) at LoopA-1
DecrementMe: 17 ; ..., 4, 3, 2
Decremented: 16 ; ..., 3, 2, 1
LimitedBy2: 2 ; ..., 2, 2, 1
AddedLoopBPlus11: LoopB+13 ; ..., LoopB+13, LoopB+13, LoopB+12
NegativeDoubleMe: 15 ; ..., -2, 4, -8
RemainderBy48: 15 ; ..., -2, 4, -8: same-sign remainder of
; NegativeDoubleMe's value divided by 48
NegativeDoubled: -30 ; ..., 4, -8. 16
IncrementMe: -1 ; ..., 1, 2, 3
Subtract4TimesMe: 0 ; ..., 2, 3, 4
Subtract4TimesFromMe: LoopB+13 ; ..., LoopB+12, LoopB+12, LoopB+12
Subtracted4Times: LoopB+9 ; ..., LoopB+4, LoopB, LoopA-1
PrintMe: "" ; contents are printed and reset to ""
; ("" = empty text = print nothing)
TEXT CONSTANTS TO BE PRINTED (numerical addresses of these locations matter)
-40: " Cll"
-39 through -25: ""
-24: " Ar"
-23 through -9: ""
-8: " Br"
-7 through 7: ""
8: " Arr"
9 through 23: ""
24: " Bl"
25 through 39: ""
40: " Cl"
41 through 44: ""
Explanation of syntax
TYPICAL INSTRUCTION, COPIES THE VALUE AT ONE LOCATION TO ANOTHER LOCATION
LoopB+13: Subtracted4Times --> ExecutionLocation ; loop back
--------- ---------------- ----------------- -----------
location whose copy the value at copy that value comment
numerical address this ocation to this location
is not -40 through 44
INSTRUCTIONS WITH BUILT-IN CONSTANTS
LoopA-1: (LoopB-4:) 'LoopA-1' --> ExecutionLocation ; halt/hang
LoopA+2: '-1' --> IncrementMe
-------- ---------- --------- ----------------- -----------
location equivalent directly copy copy that constant comment
whose location the constant to this location
numerical between ' ' quotes,
address is with no look-up
not -40 through 44
LOCATIONS WITH TEXT CONSTANTS
-40: " Cll"
-39 through -25: ""
---------------- ------
location whose text
numerical address constant to
is specific be printed
location(s) whose numerical address is explicit
LoopB+9: @ RemainderBy48 --> PrintMe
( @ RemainderBy48 means: FROM Location is specified by
the value found at RemainderBy48 )