132 lines
5.3 KiB
Text
132 lines
5.3 KiB
Text
[Pangram checker for Rosetta Code.
|
|
EDSAC program, Initial Orders 2.]
|
|
|
|
[Outline: Make a table, one entry per 5-bit character code.
|
|
Initialize entry for each letter to 1.
|
|
When a letter is read, convert its entry to 0.]
|
|
|
|
[Subroutine to read string from the input and
|
|
store it with character codes in low 5 bits.
|
|
String is terminated by blank row of tape, which is stored.
|
|
Input: 0F holds address of string in address field (bits 1..11).
|
|
21 locations; workspace: 4F]
|
|
T 56 K
|
|
GKA3FT17@AFA18@T7@I4FA4FUFS19@G12@S20@G16@T4FA7@A2FE4@T4FEFUFP8FPD
|
|
|
|
[*************** Rosetta Code task ***************
|
|
Subroutine to test whether string is a pangram.
|
|
Input: 0F = address of string, characters in low 5 bits,
|
|
terminated by blank row of tape.
|
|
Output: 1F = (number of missing letters) - 1.
|
|
87 memory locations; workspace 4F.]
|
|
T 88 K
|
|
G K
|
|
A 3 F [make and plant link for return]
|
|
T 48 @
|
|
[Fill letter table with 1's.
|
|
The code is a bit neater if we work backwards.]
|
|
A 54 @ [index of last entry]
|
|
[3] A 51 @ [make T order for table entry]
|
|
T 6 @ [plant in code]
|
|
A 53 @ [acc := 1]
|
|
[6] T F [table entry := 1]
|
|
A 6 @ [dec address in table]
|
|
S 2 F
|
|
S 51 @ [finished table?]
|
|
E 3 @ [loop back if not]
|
|
[Set non-letters to 0, except blank row := -1]
|
|
T 4 F [clear acc]
|
|
T 66 @ [figures shift]
|
|
T 70 @ [letters shift]
|
|
T 73 @ [carriage return]
|
|
T 75 @ [space]
|
|
T 79 @ [line feed]
|
|
S 53 @ [acc := -1]
|
|
T 71 @ [blank row of tape]
|
|
[Loop to read characters from string.
|
|
Terminated by blank row of tape.
|
|
Assume acc = 0 here.]
|
|
A F [load address of string]
|
|
A 49 @ [make order to read first char]
|
|
[21] T 22 @ [plant in code]
|
|
[22] A F [char to acc]
|
|
L D [shift to address field]
|
|
A 50 @ [make A order for this char in table]
|
|
U 28 @ [plant in code]
|
|
A 52 @ [convert to T order]
|
|
T 31 @ [plant in code]
|
|
[28] A F [load table entry]
|
|
G 35 @ [jump out if it's -1, i.e. blank row]
|
|
T 4 F [clear acc]
|
|
[31] T F [table entry := 0 to flag that letter is present]
|
|
A 22 @ [inc address in input string]
|
|
A 2 F
|
|
G 21 @ [back to read next char]
|
|
[Get total of table entries, again working backwards.
|
|
The number of missing letters is (total + 1).]
|
|
[35] T 4 F [clear acc]
|
|
T 1 F [initialize total := 0]
|
|
A 54 @ [index of last entry]
|
|
[38] A 50 @ [make A order for table entry]
|
|
T 41 @ [plant in code]
|
|
A 1 F [load total so far]
|
|
[41] A F [add table entry]
|
|
T 1 F [update total]
|
|
A 41 @ [load A order]
|
|
S 2 F [dec address]
|
|
S 50 @ [finished table?]
|
|
E 38 @ [loop back if not]
|
|
T 4 F [clear acc before exit]
|
|
[48] E F
|
|
[Constants]
|
|
[49] A F [to make A order referring to input]
|
|
[50] A 55 @ [to make A order referring to table]
|
|
[51] T 55 @ [to make T order referring to table]
|
|
[52] O F [add to A order to convert to T order]
|
|
[53] P D [constant 1]
|
|
[54] P 31 F [to change address by 31]
|
|
[Table]
|
|
[55] PFPFPFPFPFPFPFPFPFPFPF
|
|
[66] PFPFPFPF [11 = figures shift]
|
|
[70] PF [15 = letters shift]
|
|
[71] PFPF [16 = blank row of tape]
|
|
[73] PFPF [18 = carriage return]
|
|
[75] PFPFPFPF [20 = space]
|
|
[79] PFPFPFPFPFPFPFPF [24 = line feed]
|
|
|
|
[Main routine to demonstrate pangram-checking subroutine]
|
|
T 200 K
|
|
G K
|
|
[Constants]
|
|
[0] P 25 @ [address for input string]
|
|
[1] N F [letter N]
|
|
[2] Y F [letter Y]
|
|
[3] K 2048 F [letter shift]
|
|
[4] @ F [carriage return]
|
|
[5] & F [line feed]
|
|
[6] K 4096 F [null char]
|
|
[Enter with acc = 0]
|
|
[7] O 3 @ [set letters shift]
|
|
[8] A @ [load address of input]
|
|
T F [pass to input subroutine in 0F]
|
|
[10] A 10 @ [call input subroutine, doesn't change 0F]
|
|
G 56 F
|
|
[12] A 12 @ [call pangram subroutine]
|
|
G 88 F
|
|
[We could print the number of missing letters,
|
|
but we'll just print 'Y' or 'N'.]
|
|
A 1 F [load (number missing) - 1]
|
|
E 18 @ [jump if not pangram]
|
|
O 2 @ [print 'Y']
|
|
G 19 @ [exit]
|
|
[18] O 1 @ [print 'N']
|
|
[19] O 4 @ [print CR, LF]
|
|
O 5 @
|
|
O 6 @ [print null to flush printer buffer]
|
|
Z F [stop]
|
|
T F [on Reset, clear acc]
|
|
E 8 @ [and test another string]
|
|
[25] [input string goes here]
|
|
E 7 Z [define entry point]
|
|
P F [acc = 0 on entry]
|
|
THE!QUICK!BROWN!FOX!JUMPS!OVER!THE!LAZY!DOG.
|