-
Notifications
You must be signed in to change notification settings - Fork 0
/
threeint.mix
543 lines (542 loc) · 11.2 KB
/
threeint.mix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
*
* THREETRAN ALGEBRAIC INTERPRETER
*
*
* D. KNUTH
* NOVEMBER, 1964
* DEBUGGED MARCH 21, 1965
*
READER EQU 16
PRINTER EQU 19
ORIG 0
ERRBUF ALF ERROR
OUTBUF ALF
ORIG *+23
RATOR ORIG *+30
RAND ORIG *+60
LOOP ORIG *+24
LCTR EQU *
*
* INITIALIZATION ROUTINE
*
ORIG 3940
READIN IN CARDAREA(READER)
ENT1 OUTBUF+1
MOVE OUTBUF(23)
ENT1 CARDAREA
1H IN 16,1(READER)
LDA 6F
STA 14,1(3:3)
LDA 1,1
CMPA 2F
JNE 3F
LDA 2,1(1=1)
JAZ 4F
3H INC1 16
CMP1 5F
JL 1B
ST1 C ???
ENTA 13
JMP ERROR
2H ALF STOP
4H ST1 Z
INC1 32
ST1 Y
ENT2 CARDAREA
ENT3 0
1H LDX 0,2
JXZ 2F
ENTA 0
NUM
JMP LSEARCH
JNE *+4
ST2 C
ENTA 12
JMP ERROR
ST2 3,1
2H ST3 15,2
LDA 1,2
CMPA WDFOR
JNE 2F
INC3 3
ST2 RAND,3
JMP 3F
2H CMPA WDEND
JNE 3F
LD4 RAND,3
ST2 14,4(4=5)
DEC3 3
3H INC2 16
CMP2 Z
JLE 1B
ST2 LOOP+1
ENT1 CARDAREA
ST1 LOOP
JMP BEGIN
5H CON 3900
6H CON 49
WDFOR ALF FOR
WDEND ALF END
*
* LEXICAL SCAN
*
ORIG LCTR
ANEXT STZ LPRENR(2=2)
NEXT LD1 C
NEXT2 INC1 16
NEXT1 J2NZ BAD
LDA 1,1(1=1)
JANZ *-3
BEGIN ENT3 0
ENT2 0
ENT4 0
STZ S
NEWCARD ENT6 1,1
ENT5 -4
ST1 C
LDA LDELIM
STA RATFOR
*
LEXSCAN ENT1 5
LDX 0,6
SLAX 5,5
ENTA 0
JXNZ 1F
ENT5 -5
INC6 1
LDX 0,6
JXZ *-2
1H CMPX=40(1-1)=(1-1)
JL 2F
INC5 1 SPECIAL CHARACTER SCANNED
SLAX 1
DECA 52
JAN SSCAN
BADCHAR ENTA 9
JMP ERROR
2H SLAX 1
IN5 1
JAZ 1B
DEC1 1
J1NZ *+2
STA TEMP
J5N *+4
ENT5 -5
INC6 1
LDX 0,6
CMPX =0=(1-1)
JE *+3
CMPX =40(1-1)=
JL 2B
ENTX 0
J1NN 2F
CMP1 =-5=
JGE *+3
ENTA 11
JMP ERROR
SLC 10,1
LDA TEMP
JMP 3F
2H SLAX 0,1
3H CMPA =30(1-1)=
JGE CONST
IDENT ENT1 ROOT
JMP SEARCH
LDA 2,1(1-1)
CMPA =1=
JG SSCAN
ST1 RAND+2,3
CMP3 =58=
JL SSCAN
NOROOM ENTA 13
JMP ERROR
CONST SRAX 5,1
NUM
STZ RAND+2,3
ST5 RAND+2,3(3-3) AT THIS POINT RI5 # 0
SRAX 5
JMP 8B ???
*
LSEARCH MUL PHI
ENT1 LROOT
SEARCH STJ 9F
ST2 TEMP
1H ENT2 0,1
CMPA 0,1
JL 2F
JG 3F
CMPX 1,1
JE 7F
JG 3F
2H LD1 2,1(2-3)
J1P 1B
LD1 Y
ST1 2,2(2-3)
JMP 4F
3H LD1 2,1(4-5)
J1P 1B
LD1 Y
ST1 2,2(4-5)
4H ENT2 4,1
ST2 Y
DEC2 3998
J2NN NOROOM
STA 0,1
STX 1,1
STZ 2,1
7H LD2 TEMP
9H JMP *
PHI CON 618033989//1000000000
*
* SYNTAX SCANNER
*
TURNSTILE ENTA 12
SSCAN STA OP
LD1 OP
LDA CONTROL,1
JAN 2F
LDX CONTROL,1(2-2)
DECX 0,4
JXNZ BAD
4H LD4 CONTROL,1(3-3)
2H STA *+1(1-2)
JMP *
UNITARY INC1 18
J4Z STACK
ENT4 0
*
COMPARE1 LD1 OP
LDA CONTROL,1
COMPARE CMPA RATOR,2(1-1)
JG STACK
LD1 RATOR,2(4-5)
DEC2 1
LDA RAND+1,3
JMP 0,1
*
STACK1 LD1 OP
STACK DEC2 29
J2NN NOROOM
INC2 30
LDA STACKT,1
STA RATOR,2
JAP LEXSCAN
STZ RATOR(2-2)
JMP ERRSTAR
*
EQUAL LDX S
JXZ COMPARE
ENTA 2
JMP SSCAN
LPREN LDA OP
INCA 9
JAZ LEXSCAN
ENTA 1
JMP ERROR
IF1 ENTA 1
STA S
JMP STACK
IF2 LDX OP
DECX 13
JXNZ BAD
LDX S
JXZ IF3
JMP BAD
REPL LDX RATOR,2(3-3)
JXNZ REPL1
BAD ENTA 10
JMP ERROR
ARRAY1 ENTX 1
STX LPRENR(2-2)
JMP STACK
LD LDX OP
DECX 12
ENTA 2
JXNZ ERROR
ENTA 14
LDX RATOR(2-2)
JXNZ ERROR
INC2 1
JMP NEXT
*
CARDEND LD1 C
LDA 17,1(1-1)
JAZ TURNSTILE
INC1 16
JMP NEWCARD
*
* GENERATORS (OPERATIONS)
SUB LDAN RAND+1,3
ADD ADD RAND-1,3
ARITH STA RAND-1,3
DEC3 2
STZ RAND,3
JMP COMPARE1
MUL MUL RAND-1,3
STX RAND-1,3
JMP ARITH+1
DIV JANZ *+3
ENTA 3
JMP ERROR
LDA RAND-1,3
SRAX 5
DIV RAND+1,3
JMP ARITH
EQL CMPA RAND-1,3
JE TRUE
FALSE ENTA 0
JMP 1F
LSS CMPA RAND-1,3
JG TRUE
JMP FALSE
GTR CMPA RAND-1,3
JG FALSE
TRUE ENTA 1
1H LDX S
DECX 1
STX S
JMP ARITH
IF3 DEC3 2
JANZ LEXSCAN
JMP NEXT
SUBSC LD1 RAND-2,3
JAN 1F
CMPA 3,1
JG 1F
INCA 1,1
STA RAND-2,3
LD1 RAND-2,3
LDA 3,1
2H STA RAND-1,3
DEC3 2
JMP COMPARE1
1H ENTA 5
JMP ERROR
REPL1 LD1 RAND-2,3
J1NZ *+3
NOVAR ENTA 4
JMP ERROR
STA 3,1
JMP 2B
NEG LDAN RAND+1,3
STA RAND+1,3
STZ RAND,3
JMP COMPARE1
OUT ENTX 0
JAP *+2
ENTX 45
JBUS *(PRINTER)
STX OUTBUF+2(1-1)
CHAR
STA OUTBUF
STX OUTBUF+1
OUT OUTBUF(PRINTER)
JMP NEXT
IN LD1 Z
JBUS *(READER)
LDA 16,1
LDX 17,1
NUM
LDX 18,1(1-1)
IN 16,1(READER)
LD1 RAND,3
J1Z NOVAR
1H STA 3,1
DECX 45
JXNZ NEXT
LDAN 3,1
JMP 1B
ARRAY DEC3 4
J3Z *+3
1H ENTA 6
JMP ERROR
LDX RAND+4(3-3)
JXZ 1B
LDX Y
LD1 RAND+2
DECX 4,1
JXNZ 1B
STA 3,1
ENTX 1
STX 2,1(1-1)
INCA 5,1
STA Y
DECA 3998
JANN NOROOM
LDA OP
DECA 12
JAZ ANEXT
INC2 1
JMP LEXSCAN
*
* FOR,END,GO AND STOP STATEMENTS
*
GO LDX RAND+3,(3-3)
JXZ BADGO
JMP LSEARCH
JNE BADGO
LD1 3,1
LD4 L
2H CMP1 LOOP,4(4-5)
JLE 1F
CMP1 LOOP+1,4(4-5)
JG 1F
ST4 L
CMP4 15,1
JEX NEXT1
BADGO ENTA 7
JMP ERROR
1H DEC4 3
JMP 2B
FOR0 EQU STACK1
FOR1 LD1 L
INC1 3
CMP1 =24=
JGE NOROOM
STA LOOP+2,1
CMPA RAND-1,3
JL 1F
ST1 L
LD4 C
ST4 LOOP,1
LDA RAND-2,3
STA LOOP,1(1-2)
LDA 14,4(4-5)
STA LOOP+1,1
JMP NEXT
1H LD1 C
LD1 14,1(4-5)
JMP NEXT2
END LD4 L
LD6 LOOP,4(1-2)
CMPA RAND,3
JNE BADFOR
LDA 3,6
INCA 1
STA 3,6
CMPA LOOP+2,4
LD1 LOOP,4(4-5)
JLE NEXT2
DEC4 3
ST4 L
JMP NEXT
*
STOP LDA L
JAZ 1F
BADFOR ENTA 8
ERROR CHAR
JBUS *(PRINTER)
STX OUTBUF(2-3)
ENT1 OUTBUF+1
LD2 C
MOVE 0,2(14)
OUT ERRBUF(PRINTER)
1H HLT *
*
* SYNTAX TABLES
*
LROOT CON 100
CON 0
CON 0
ROOT ALF IF
ALF
CON *+4,*+1(2-3),3(1-1)
ALF FOR
ALF
CON *+7,*+4(2-3),4(1-1)
ALF OUTPU
ALF T
CON *+10,*+7(2-3),5(1-1)
ALF COMME
ALF NT
CON *+13,*+10(2-3),15(1-1)
ALF GO
ALF
CON 7(1-1)
ALF LOOP
ALF
CON *+10(2-3),10(1-1)
ALF THEN
ALF
CON *+13,*+10(2-3),13(1-1)
ALF ARRAY
ALF
CON 9(1-1)
ALF END
ALF
CON 8(1-1)
ALF INPUT
ALF
CON 6(1-1)
ALF STOP
ALF
CON 14(1-1)
ALF TO
ALF
CON 10(1-1)
*
CON FOR1,1(1-1)
CON LPREN
CON 0
CON ADD,3(1-1)
CON SUB,3(1-1)
CON MUL,5(1-1)
CON DIV,5(1-1)
CON -REPL,1(3-3)
CON 0
CON LSS,1(1-1)
CON GTR,1(1-1)
STACKT CON 0
CON SUBSC,6(1-1)
CON EQL,1(1-1)
CON IF2
CON FOR0,1(3-3)
CON OUT
CON IN
CON GO
CON END
CON ARRAY
CON COMPARE1
CON NEG,5(1-1)
LDELIM CON LD,1(2-2)
*
CON -BADCHAR
CON COMPARE,1(2-2)
LPRENR CON STACK
CON COMPARE,1(2-2),1(3-3)
CON -UNITARY,2(1-1)
CON -UNITARY,2(1-1)
CON COMPARE,4(1-1),1(2-2)
CON COMPARE,4(1-1),1(2-2)
CON EQUAL,2(1-1),1(2-2)
CON -CARDEND,1(2-2)
CON COMPARE,2(1-1),1(2-2)
CON COMPARE,2(1-1),1(2-2)
CONTROL CON LEXSCAN,1(3-3)
CON STACK
CON COMPARE,2(1-1)
CON IF1
CON STACK
CON STACK
CON STACK
CON STACK
CON STACK
CON ARRAY1
CON LEXSCAN
CON STACK
CON COMPARE,1(2-2)
CON COMPARE,1(2-2)
CON STOP
CON NEXT
*
* VARIABLES AND INTERPRETED PROGRAM AREA
*
Z CON 0
Y CON 0
C CON 0
OP CON 0
S CON 0
L CON 0
TEMP CON 0
CARDAREA EQU *+10
END READIN