RosettaCodeData/Task/Babbage-problem/EDSAC-order-code/babbage-problem.edsac

80 lines
2.9 KiB
Plaintext

[Babbage problem from Rosetta Code website]
[EDSAC program, Initial Orders 2]
[Library subroutine M3. Pauses the loading, prints header,
and gets overwritten when loading resumes.
Here, the last character sets the teleprinter to figures.]
PFGKIFAFRDLFUFOFE@A6FG@E8FEZPF
@&*SOLUTION!TO!BABBAGE!PROBLEM@&#
..PZ [blank tape, needed to mark end of header text]
[Library subroutine P6. Prints strictly positive integer.
32 locations; argument at 0, working locations 1, 4, 5]
T56K [define load address for subroutine]
GKA3FT25@H29@VFT4DA3@TFH30@S6@T1FV4DU4DAFG26@
TFTFO5FA4DF4FS4FL4FT4DA1FS3@G9@EFSFO31@E20@J995FJF!F
[Main routine. Load after subroutine P6.
Must be at an even address because each double
value at the start must be at an even address.]
T88K [define absolute load address]
GK [set @ (theta) for relative addresses]
[Variables]
[0] PF PF [trial solution, call it n]
[2] PF PF [residue of n^2 modulo 1000000]
[4] PF PF [1st difference for n^2]
[Constants]
[2024-12-25 Load time: clear each 35-bit constant, including sandwich bit]
T6#ZPF T8#ZPF T10#ZPF T12#ZPF
[Then resume normal loading at first 35-bit constant]
T6Z
[6] P64F PF [2nd difference for n^2, i.e. 128]
[8] P4F PF [1st difference for n, i.e. 8]
[10] #1760F V2046F [-1000000]
[12] Q1728F PD [269696]
[14] &F [line feed]
[15] @F [carriage return]
[16] K4096F [teleprinter null]
[Enter with acc = 0]
[17] T#@ [trial number n := 0]
T2#@ [(n^2 mod 1000000) := 0]
S6#@ [acc := -128]
RD [right shift]
T4#@ [(1st difference for n^2) := -64]
[Start of loop]
[22] TF [clear acc]
A#@ [load n]
A8#@ [add 8]
T#@ [update n]
A4#@ [load 1st difference of n^2]
A6#@ [add 128]
T4#@ [update]
A2#@ [load residue of n^2 mod 1000000]
A4#@ [add 1st difference]
[31] A10#@ [subtract 1000000, by adding -1000000]
E31@ [repeat until result < 0]
S10#@ [add back 1000000]
U2#@ [update residue]
S12#@ [subtract target 269696]
G22@ [loop back if residue < 269696]
[if still here, acc is non-neg mult of 64]
S8#@ [test for acc = 0 by subtracting 8]
E22@ [loop back if residue > 269696]
[Here with the solution]
TF [clear acc]
A#@ [load solution n]
TD [store at absolute address 0 for printing]
[42] A42@ [for return from subroutine]
G56F [call subroutine to print n]
O15@ [print CR]
O14@ [print LF]
O16@ [print null, to flush printer buffer]
ZF [stop]
E17Z [define entry point]
PF [enter with acc = 0]