115 lines
4.2 KiB
Text
115 lines
4.2 KiB
Text
[Hundred doors problem from Rosetta Code website]
|
|
[EDSAC program, Initial Orders 2]
|
|
|
|
[Library subroutine M3. Prints header and is then overwritten.
|
|
Here, the last character sets the teleprinter to figures.]
|
|
PFGKIFAFRDLFUFOFE@A6FG@E8FEZPF
|
|
@&*THE!OPEN!DOORS!ARE@&#
|
|
..PZ [blank tape, needed to mark end of header text]
|
|
|
|
[Library subroutine P6. Prints strictly positive integer.
|
|
32 locations; working locations 1, 4, 5]
|
|
T56K [define load address for subroutine]
|
|
GKA3FT25@H29@VFT4DA3@TFH30@S6@T1F
|
|
V4DU4DAFG26@TFTFO5FA4DF4FS4F
|
|
L4FT4DA1FS3@G9@EFSFO31@E20@J995FJF!F
|
|
|
|
T88K [define load address for main program]
|
|
GK [set @ (theta) for relative addresses]
|
|
|
|
[The 100 doors are at locations 200..299.
|
|
Doors are numbered 0..99 internally, and 1..100 for output.
|
|
The base address and the number of doors can be varied.
|
|
The value of a door is 0 if open, negative if closed.]
|
|
|
|
[Constants. Program also uses order 'P 1 F'
|
|
which is permanently at absolute address 2.]
|
|
[0] P200F [address of door #0]
|
|
[1] P100F [number of doors, as an address]
|
|
[2] UF [makes S order from T, since 'S' = 'T' + 'U']
|
|
[3] MF [makes A order from T, since 'A' = 'T' + 'M']
|
|
[4] V2047D [all 1's for "closed" (any negative value will do)]
|
|
[5] &F [line feed]
|
|
[6] @F [carriage return]
|
|
[7] K4096F [teleprinter null[
|
|
|
|
[Variables]
|
|
[8] PF [pass number; step when toggling doors]
|
|
[9] PF [door number, as address, 0-based]
|
|
[10] PF [order referring to door 0]
|
|
|
|
[Enter with acc = 0]
|
|
[Part 1 : close all the doors]
|
|
[11] T8@ [pass := 0 (used in part 2)]
|
|
T9@ [door number := 0]
|
|
A16@ [load 'T F' order]
|
|
A@ [add base address]
|
|
T10@ [store T order for door #0]
|
|
[16] TF [clear acc; also serves as constant]
|
|
A9@ [load door number]
|
|
A10@ [make T order]
|
|
T21@ [plant in code]
|
|
A4@ [load value for "closed"]
|
|
[21] TF [store in current door]
|
|
A9@ [load door number]
|
|
A2F [add 1]
|
|
U9@ [update door number]
|
|
S1@ [done all doors yet?]
|
|
G16@ [if not, loop back]
|
|
|
|
[Part 2 : 100 passes, toggling the doors]
|
|
[27] TF [clear acc]
|
|
A8@ [load pass number]
|
|
A2F [add 1]
|
|
T8@ [save updated pass number]
|
|
S2F [make -1]
|
|
U9@ [door number := -1]
|
|
A8@ [add pass number to get first door toggled on this pass]
|
|
S1@ [gone beyond end?]
|
|
E50@ [if so, move on to part 3]
|
|
[36] A1@ [restore acc after test]
|
|
U9@ [store current door number]
|
|
A10@ [make T order to load status]
|
|
U44@ [plant T order for first door in pass]
|
|
A2@ [convert to S order]
|
|
T43@ [plant S order]
|
|
A4@ [load value for "closed"]
|
|
[43] SF [subtract status; toggles status]
|
|
[44] TF [update status]
|
|
A9@ [load door number just toggled]
|
|
A8@ [add pass number to get next door in pass]
|
|
S1@ [gone beyond end?]
|
|
G36@ [no, loop to do next door]
|
|
E27@ [yes, loop to do next pass]
|
|
|
|
[Part 3 : Print list of open doors.
|
|
Header has set teleprinter to figures.]
|
|
[50] TF [clear acc]
|
|
T9@ [door nr := 0]
|
|
A10@ [T order for door 0]
|
|
A3@ [convert to A order]
|
|
T10@
|
|
[55] TF
|
|
A9@ [load door number]
|
|
A10@ [make A order to load value]
|
|
T59@ [plant in next order]
|
|
[59] AF [acc := 0 if open, < 0 if closed]
|
|
G69@ [skip if closed]
|
|
A9@ [door number as address]
|
|
A2F [add 1 for 1-based output]
|
|
RD [shift 1 right, address --> integer]
|
|
TF [store integer at 0 for printing]
|
|
[65] A65@ [for return from subroutine]
|
|
G56F [call subroutine to print door number]
|
|
O6@ [followed by CRLF]
|
|
O5@
|
|
[69] TF [clear acc]
|
|
A9@ [load door number]
|
|
A2F [add 1]
|
|
U9@ [update door number]
|
|
S1@ [done all doors yet?]
|
|
G55@ [if not, loop back]
|
|
[75] O7@ [output null to flush teleprinter buffer]
|
|
ZF [stop]
|
|
E11Z [define relative start address]
|
|
PF
|