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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
|
This is mdk.info, produced by makeinfo version 6.7 from mdk.texi.
This manual is for GNU MDK (version 1.2.9, November, 2015), a set of
utilities for developing programs using Donald Knuth's MIX mythical
computer and MIXAL, its assembly language.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
2010, 2013, 2014, 2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software
Foundation; with the Invariant Sections being "GNU General Public
License", with the Front-Cover Texts being "A GNU Manual," and with
the Back-Cover Texts as in (a) below. A copy of the license is
included in the section entitled "GNU Free Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom."
INFO-DIR-SECTION GNU programming tools
START-INFO-DIR-ENTRY
* MDK: (mdk). The GNU MIX Development Kit.
END-INFO-DIR-ENTRY
File: mdk.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
This manual is for GNU MDK (version 1.2.9, November, 2015), a set of
utilities for developing programs using Donald Knuth's MIX mythical
computer and MIXAL, its assembly language.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
2010, 2013, 2014, 2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software
Foundation; with the Invariant Sections being "GNU General Public
License", with the Front-Cover Texts being "A GNU Manual," and with
the Back-Cover Texts as in (a) below. A copy of the license is
included in the section entitled "GNU Free Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom."
GNU MDK was written and designed by Jose Antonio Ortega Ruiz.
Pieter E. J. Pareit is the author of the Emacs 'MIXAL' mode (*note
MIXAL mode::), and has also contributed many bug fixes.
Philip E. King has contributed to this package development with many
helpful discussions, as well as actual code (*note GUD integration::).
Michael Scholz is the author of the German translation of MDK's user
interface.
* Menu:
* Introduction::
* Acknowledgments::
* Installing MDK:: Installing GNU MDK from the source tarball.
* MIX and MIXAL tutorial:: Learn the innards of MIX and MIXAL.
* Getting started:: Basic usage of the MDK tools.
* Emacs tools:: Programming the MIX using Emacs.
* mixasm:: Invoking the MIXAL assembler.
* mixvm:: Invoking and using the MIX virtual machine.
* gmixvm:: Invoking and using the GTK+ virtual machine.
* mixguile:: Invoking and using the Scheme virtual machine.
* Problems:: Reporting bugs.
* Copying:: MDK licensing terms.
* Concept Index:: Index of concepts.
* Instructions and commands:: Index of MIXAL instructions and MIXVM commands.
-- The Detailed Node Listing --
Installing MDK
* Download::
* Requirements::
* Basic installation::
* Emacs support::
* Special configure flags::
* Supported platforms::
MIX and MIXAL tutorial
* The MIX computer:: Architecture and instruction set
of the MIX computer.
* MIXAL:: The MIX assembly language.
The MIX computer
* MIX architecture::
* MIX instruction set::
MIX instruction set
* Instruction structure::
* Loading operators::
* Storing operators::
* Arithmetic operators::
* Address transfer operators::
* Comparison operators::
* Jump operators::
* Input-output operators::
* Conversion operators::
* Shift operators::
* Miscellaneous operators::
* Execution times::
MIXAL
* Basic structure:: Writing basic MIXAL programs.
* MIXAL directives:: Assembler directives.
* Expressions:: Evaluation of expressions.
* W-expressions:: Evaluation of w-expressions.
* Local symbols:: Special symbol table entries.
* Literal constants:: Specifying an immediate operand.
Getting started
* Writing a source file:: A sample MIXAL source file.
* Compiling:: Using 'mixasm' to compile source
files into binary format.
* Running the program:: Running and debugging your programs.
* Using mixguile:: Using the Scheme interpreter to run and
debug your programs.
* Using Scheme in mixvm and gmixvm::
Running the program
* Non-interactive mode:: Running your programs non-interactively.
* Interactive mode:: Running programs interactively.
* Debugging:: Commands for debugging your programs.
Using 'mixguile'
* The mixguile shell:: Using the Scheme MIX virtual machine.
* Additional functions:: Scheme functions accessing the VM.
* Defining new functions:: Defining your own Scheme functions.
* Hook functions:: Using command and break hook functions.
* Scheme scripts::
Hook functions
* Command hooks::
* Break hooks::
Emacs tools
* MIXAL mode:: Editing MIXAL files.
* GUD integration:: Invoking 'mixvm' within Emacs.
MIXAL mode
* Basics:: Editing code, font locking and indentation.
* Help system:: Using the interactive help system.
* Compiling and running:: Invoking compiler and/or virtual machine.
'mixasm', the MIXAL assembler
* Invoking mixasm::
'mixvm', the MIX computer simulator
* Invocation::
* Commands:: Commands available in interactive mode.
* Devices:: MIX block devices implementation.
Interactive commands
* File commands:: Loading and executing programs.
* Debug commands:: Debugging programs.
* State commands:: Inspecting the virtual machine state.
* Configuration commands:: Changing and storing mixvm settings.
* Scheme commands::
'gmixvm', the GTK virtual machine
* Invoking gmixvm::
* MIXVM console:: Using 'mixvm' commands.
* MIX virtual machine:: The MIX virtual machine window.
* MIXAL source view:: Viewing the MIXAL source code.
* MIX devices view:: Device output.
* Menu and status bars:: Available menu commands.
'mixguile', the Scheme virtual machine
* Invoking mixguile:: Command line options.
* Scheme functions reference:: Scheme functions accessing the VM.
Scheme functions reference
* mixvm wrappers:: Functions invoking mixvm commands.
* Hooks:: Adding hooks to mixvm commands.
* Additional VM functions:: Functions accessing the MIX virtual machine.
Copying
* GNU General Public License::
* GNU Free Documentation License::
File: mdk.info, Node: Introduction, Next: Acknowledgments, Prev: Top, Up: Top
Introduction
************
In his book series 'The Art of Computer Programming' (published by
Addison Wesley), D. Knuth uses an imaginary computer, the MIX, and its
associated machine-code and assembly languages to illustrate the
concepts and algorithms as they are presented.
The MIX's architecture is a simplified version of those found in real
CISC CPUs, and the MIX assembly language (MIXAL) provides a set of
primitives that will be very familiar to any person with a minimum
experience in assembly programming. The MIX/MIXAL definition is
powerful and complete enough to provide a virtual development platform
for writing quite complex programs, and close enough to real computers
to be worth using when learning programming techniques. At any rate, if
you want to learn or improve your programming skills, a MIX development
environment would come in handy.
The MDK package aims at providing such virtual development
environment on a GNU box. Thus, MDK offers you a set of utilities to
simulate the MIX computer and to write, compile, run and debug MIXAL
programs. As of version 1.2.9, MDK includes the following programs:
'mixasm'
MIXAL assembler. Assembler which translates MIXAL source files
into programs that can be run (and debugged) by 'mixvm', 'mixguile'
or 'gmixvm'.
'mixvm'
MIX virtual machine. Emulation of the MIX computer with a CLI.
'gmixvm'
A GTK+ GUI for the MIX virtual machine. Provides all of 'mixvm'
functionality accessible through a graphical interface.
'mixguile'
A Guile shell, with an embedded MIX virtual machine and built-in
commands to manipulate it using Scheme.
'mixal-mode.el'
An Emacs major mode for MIXAL source files editing, providing
syntax highlighting, documentation lookup and invocation of 'mixvm'
within Emacs.
'mixvm.el'
This elisp program allows running 'mixvm' inside an Emacs GUD
buffer, providing concurrent edition and debugging of MIXAL
programs.
'mixvm' and 'gmixvm' implement a simulator of the MIX computer,
giving you a virtual machine for executing and debugging MIX programs.
These binary programs could be written by hand, but it is easier to
produce them compiling MIXAL source files, using the MIXAL assembler
'mixasm'. On the other hand, 'mixguile' offers you the possibility of
manipulating a MIX virtual machine through a set of Scheme functions, so
that you can use this programming language to interact with the virtual
machine. In addition, 'mixvm' and 'gmixvm' are also able to interpret
Scheme scripts (using an embedded Guile interpreter), that is, you can
use Scheme as an extension language to add new functionalities to these
programs.
This manual gives you a tutorial of MIX and MIXAL, and a thorough
description of the use of the MDK utilities.
File: mdk.info, Node: Acknowledgments, Next: Installing MDK, Prev: Introduction, Up: Top
Acknowledgements
****************
Many people have further contributed to MDK by reporting problems,
suggesting various improvements, or submitting actual code. Here is a
list of these people. Please, help me keep it complete and exempt of
errors.
* Philip Ellis King provided MIXAL test programs pinpointing bugs in
the first MDK release, and useful discussions as well. Philip has
also contributed with the Emacs port of 'mixvm' and influenced the
'gmixvm' GUI design with insightful comments and prototypes.
* Aleix Conchillo has been following MDK's development for many
years, indefatigably chasing and fixing bugs, and suggesting many
improvements. He's also the original author of the Fink and
Macports ports.
* Pieter E J Pareit is the author of the Emacs MIXAL mode, and has
also contributed many bug fixes.
* Michael Scholz is the author of the German translation of MDK's
user interface.
* Sergey Poznyakoff provided patches to mixlib/mix_scanner.l
improving MIXAL compliance.
* Sergey Litvin implemented the instructions 'SLB', 'SRB', 'JAE',
'JAO', 'JXE', and 'JXO' from volume 2 of TAOCP.
* Francesc Xavier Noria kindly and thoroughly reviewed the MDK
documentation, providing insightful advice.
* Eric S. Raymond contributed the documentation file 'MIX.DOC' and
the samples 'elevator.mixal' and 'mistery.mixal' from his MIXAL
package.
* Nelson H. F. Beebe has tested MDK in a lot of Unix platforms,
suggesting portability enhancements to the source code.
* Ryan Schmidt, Agustin Navarro, Ying-Chieh Liao, Adrian Bunk, Baruch
Even, and Ronald Cole ported MDK to different platforms, and
created and/or maintain packages for it.
* Jason Uhlenkott, Andrew Hood, Radu Butnaru, Ruslan Batdalov,
WeiZheng, Sascha Wilde, Michael Vernov and Xiaofeng Zhao reported
bugs and suggested fixes to them.
* Joshua Davies, Eli Bendersky, Milan Bella and Jens Seidel reported
bugs on the documentation.
* Christoph von Nathusius, Stephen Ramsay and Johan Swanljung tested
MDK on different platforms, and helped fixing the configuration
process in them.
* Richard Stallman suggested various improvements to the
documentation and has always kept an eye on each MDK release.
* MDK was inspired by Darius Bacon's MIXAL program
(http://www.accesscom.com/~darius/).
File: mdk.info, Node: Installing MDK, Next: MIX and MIXAL tutorial, Prev: Acknowledgments, Up: Top
1 Installing MDK
****************
* Menu:
* Download::
* Requirements::
* Basic installation::
* Emacs support::
* Special configure flags::
* Supported platforms::
File: mdk.info, Node: Download, Next: Requirements, Prev: Installing MDK, Up: Installing MDK
1.1 Download the source tarball
===============================
GNU MDK is distributed as a source tarball available for download in the
following URLs:
* <ftp://ftp.gnu.org/pub/gnu/mdk>
* GNU mirrors (http://www.gnu.org/prep/ftp.html)
The above sites contain the latest stable releases of MDK. The
development branch is available as a Git (http://git-scm.com/)
repository located at(1) (*note Download-Footnote-1::)
* <git://git.savannah.gnu.org/mdk.git>
After you have downloaded the source tarball, unpack it in a
directory of your choice using the command:
tar xfvz mdk-X.Y.tar.gz
where X.Y stands for the downloaded version (the current stable release
being version 1.2.9).
File: mdk.info, Node: Download-Footnotes, Up: Download
(1) See MDK's Git page (https://savannah.gnu.org/git/?group=mdk) for
more information on using the unstable source tree. Note, however, that
the rest of this manual is about the _stable_ release.
File: mdk.info, Node: Requirements, Next: Basic installation, Prev: Download, Up: Installing MDK
1.2 Requirements
================
In order to build and install MDK, you will need the following libraries
installed in your system:
- GLIB 2.16.0 (http://www.gtk.org) (required)
- GNU Flex 2.5 (http://www.gnu.org/software/flex/flex.html)
(required)
- GTK 2.16.0 (http://www.gtk.org) (optional)
- Libglade 2.6.0
(http://ftp.gnome.org/pub/GNOME/sources/libglade/2.6/) (optional)
- GNU Readline
(http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html)
(optional)
- GNU Libguile 2.0 (http://www.gnu.org/software/guile) (optional)
If present, readline and history are used to provide command
completion and history management to the command line MIX virtual
machine, 'mixvm'. GTK+ and libglade are needed if you want to build the
graphical interface to the MIX virtual machine, 'gmixvm'. Finally, if
libguile is found, the MDK utilities will be compiled with Guile support
and will be extensible using Scheme.
*Please note*: you need both the libraries _and_ the headers; this
means both the library package and the '-dev' package if you do not
compile your libraries yourself (ex: installing 'libgtk2.0-0' and
'libgtk2.0-0-dev' on Debian).
File: mdk.info, Node: Basic installation, Next: Emacs support, Prev: Requirements, Up: Installing MDK
1.3 Basic installation
======================
MDK uses GNU Autoconf and Automake tools, and, therefore, should be
built and installed without hassle using the following commands inside
the source directory:
./configure
make
make install
where the last one must be run as root.
The first command, 'configure', will setup the makefiles for your
system. In particular, 'configure' will look for GTK+ and libglade,
and, if they are present, will generate the appropriate makefiles for
building the 'gmixvm' graphical user interface. Upon completion, you
should see a message with the configuration results like the following:
*** GNU MDK 1.2.9 has been successfully configured. ***
Type 'make' to build the following utilities:
- mixasm (MIX assembler)
- mixvm (MIX virtual machine, with readline support,
with guile support)
- gmixvm (mixvm GTK+ GUI, with guile support)
- mixguile (the mixvm guile shell)
where the last lines may be missing if you lack the above mentioned
libraries.
The next command, 'make', will actually build the MDK programs in the
following locations:
- 'mixutils/mixasm'
- 'mixutils/mixvm'
- 'mixgtk/gmixvm'
- 'mixguile/mixguile'
You can run these programs from within their directories, but I
recommend you to install them in proper locations using 'make install'
from a root shell.
File: mdk.info, Node: Emacs support, Next: Special configure flags, Prev: Basic installation, Up: Installing MDK
1.4 Emacs support
=================
MDK includes extensive support for Emacs. Upon installation, all the
elisp code is installed in 'PREFIX/share/mdk', where 'PREFIX' stands for
your installation root directory (e.g. '/usr/local'). You can copy the
elisp files to a directory that is in your load-path, or you can add the
above directory to it. Assuming that the installing prefix is
'/usr/local', you can do it by adding to your '.emacs' file the
following line:
(setq load-path (cons "/usr/local/share/mdk" load-path))
'MIXAL' programs can be written using Emacs and the elisp program
'share/mdk/mixal-mode.el', contributed by Pieter E. J. Pareit. It
provides font locking, interactive help, compiling assistance and
invocation of the 'MIX' virtual machine via a new major mode called
'mixal-mode'. To start 'mixal-mode' automatically whenever you edit a
'MIXAL' source file, add the following lines to your '.emacs' file:
(autoload 'mixal-mode "mixal-mode" t)
(add-to-list 'auto-mode-alist '("\\.mixal\\'" . mixal-mode))
In addition, 'mixvm' can be run within an Emacs GUD buffer using the
elisp program 'share/mdk/mixvm.el', contributed by Philip E. King.
'mixvm.el' provides an interface between MDK's 'mixvm' and Emacs, via
GUD. Place this file in your load-path, optionally adding the following
line to your '.emacs' file:
(autoload 'mixvm "mixvm" "mixvm/gud interaction" t)
File: mdk.info, Node: Special configure flags, Next: Supported platforms, Prev: Emacs support, Up: Installing MDK
1.5 Special configure flags
===========================
You can fine-tune the configuration process using the following switches
with configure:
-- User Option: --enable-gui[=yes|no]
-- User Option: --disable-gui
Enables/disables the build of the MIX virtual machine GUI
('gmixvm'). If the required libraries are missing (*note
Requirements::) the configure script with automatically disable
this feature.
-- User Option: --with-guile[=yes|no]
-- User Option: --without-guile
Enables/disables the Guile support for 'mixvm' and 'gmixvm', and
the build of 'mixguile'. If the required libraries are missing
(*note Requirements::) the configure script with automatically
disable this feature.
-- User Option: --with-readline[=yes|no]
-- User Option: --without-readline
Enables/disables the GNU Readline support for 'mixvm'. If the
required libraries are missing (*note Requirements::) the configure
script with automatically disable this feature.
For additional, boilerplate configure options, see the 'INSTALL'
file, or run
configure --help
File: mdk.info, Node: Supported platforms, Prev: Special configure flags, Up: Installing MDK
1.6 Supported platforms
=======================
GNU MDK has been tested in the following platforms:
* Debian GNU/Linux 2.2, 2.3, 3.0, 3.1, 3.2, 4.0, 5.0, 6.0, sid
* Redhat GNU/Linux 8.0 (Ronald Cole), 7.0 (Agustin Navarro), 6.2
(Roberto Ferrero)
* Mandrake 8.0 (Agustin Navarro)
* FreeBSD 4.2, 4.3, 4.4, 4.5 (Ying-Chieh Liao), 5.2
* Solaris 2.8/gcc 2.95.3 (Stephen Ramsay)
* MS Windows 98 SE/Cygwin 1.1.8-2 (Christoph von Nathusius)(1) (*note
Supported platforms-Footnote-1::)
* Mac OS X 10.1.2 (Johan Swanljung), Mac OS X 10.4.x, 10.5 (Darwin
Port by Aleix Conchillo).
* AMD Athlon, GNU/Linux version 2.4.2-2smp (Red Hat 7.1 (Seawolf))
(N. H. F. Beebe)
* Apple PowerPC G3, GNU/Linux 2.2.18-4hpmac (Red Hat Linux/PPC 2000
Q4) (N. H. F. Beebe)
* DEC Alpha, GNU/Linux 2.2.19-6.2.1 (Red Hat 6.2) (N. H. F. Beebe)
* Compaq/DEC Alpha OSF/1 4.0F [ONLY after adding rsync's snprintf()
implementation] (N. H. F. Beebe)
* IBM PowerPC AIX 4.2 (N. H. F. Beebe)
* Intel Pentium III, GNU/Linux 2.4.9-31smp (Red Hat 7.2 (Enigma)) (N.
H. F. Beebe)
* SGI Origin 200, IRIX 6.5 (N. H. F. Beebe)
* Sun SPARC, GNU/Linux 2.2.19-6.2.1 (Red Hat 6.2) (N. H. F. Beebe)
* Sun SPARC, Solaris 2.8 (N. H. F. Beebe)
MDK will probably work on any GNU/Linux or BSD platform. If you try
it in a platform not listed above, please send a mail to the author
<jao@gnu.org>.
File: mdk.info, Node: Supported platforms-Footnotes, Up: Supported platforms
(1) Caveats: Christoph has only tested 'mixvm' and 'mixasm' on this
platform, using 'gcc' 2.95.3-2, 'GLIB' 1.2.10 and 'GNU readline' 4.1-2.
He has reported missing history functionalities on a first try. If you
find problems with history/readline functionality, please try a
newer/manually installed readline version.
File: mdk.info, Node: MIX and MIXAL tutorial, Next: Getting started, Prev: Installing MDK, Up: Top
2 MIX and MIXAL tutorial
************************
In the book series 'The Art of Computer Programming', by D. Knuth, a
virtual computer, the MIX, is used by the author (together with the set
of binary instructions that the virtual CPU accepts) to illustrate the
algorithms and skills that every serious programmer should master. Like
any other real computer, there is a symbolic assembler language that can
be used to program the MIX: the MIX assembly language, or MIXAL for
short. In the following subsections you will find a tutorial on these
topics, which will teach you the basics of the MIX architecture and how
to program a MIX computer using MIXAL.
* Menu:
* The MIX computer:: Architecture and instruction set
of the MIX computer.
* MIXAL:: The MIX assembly language.
File: mdk.info, Node: The MIX computer, Next: MIXAL, Prev: MIX and MIXAL tutorial, Up: MIX and MIXAL tutorial
2.1 The MIX computer
====================
In this section, you will find a description of the MIX computer, its
components and instruction set.
* Menu:
* MIX architecture::
* MIX instruction set::
File: mdk.info, Node: MIX architecture, Next: MIX instruction set, Prev: The MIX computer, Up: The MIX computer
2.1.1 MIX architecture
----------------------
The basic information storage unit in the MIX computer is the "byte",
which stores positive values in the range 0-63 . Note that a MIX byte
can be then represented as 6 bits, instead of the common 8 bits for a
_regular_ byte. Unless otherwise stated, we shall use the word "byte"
to refer to a MIX 6-bit byte.
A MIX "word" is defined as a set of 5 bytes plus a sign. The bytes
within a word are numbered from 1 to 5, being byte number one the most
significant one. The sign is denoted by index 0. Graphically,
-----------------------------------------------
| 0 | 1 | 2 | 3 | 4 | 5 |
-----------------------------------------------
| +/- | byte | byte | byte | byte | byte |
-----------------------------------------------
Sample MIX words are '- 12 00 11 01 63' and '+ 12 11 34 43 00'.
You can refer to subfields within a word using a "field
specification" or "fspec" of the form "(L:R)", where L denotes the first
byte, and R the last byte of the subfield. When L is zero, the subfield
includes the word's sign. An fspec can also be represented as a single
value 'F', given by 'F = 8*L + R' (thus the fspec '(1:3)', denoting the
first three bytes of a word, is represented by the integer 11).
The MIX computer stores information in "registers", that can store
either a word or two bytes and sign (see below), and "memory cells",
each one containing a word. Specifically, the MIX computer has 4000
memory cells with addresses 0 to 3999 (i.e., two bytes are enough to
address a memory cell) and the following registers:
'rA'
A register. General purpose register holding a word. Usually its
contents serves as the operand of arithmetic and storing
instructions.
'rX'
X register. General purpose register holding a word. Often it
acts as an extension or a replacement of 'rA'.
'rJ'
J (jump) register. This register stores positive two-byte values,
usually representing a jump address.
'rI1', 'rI2', 'rI3', 'rI4', 'rI5', 'rI6'
Index registers. These six registers can store a signed two-byte
value. Their contents are used as indexing values for the
computation of effective memory addresses.
In addition, the MIX computer contains:
- An "overflow toggle" (a single bit with values "on" or "off"). In
this manual, this toggle is denoted OV.
- A "comparison indicator" (having three values: "EQUAL", "GREATER"
or "LESS"). In this manual, this indicator is denoted CM, and its
possible values are abbreviated as "E", "G" and "L".
- Input-output block devices. Each device is labelled as 'un', where
'n' runs from 0 to 20. In Knuth's definition, 'u0' through 'u7'
are magnetic tape units, 'u8' through '15' are disks and drums,
'u16' is a card reader, 'u17' is a card writer, 'u18' is a line
printer and, 'u19' is a typewriter terminal, and 'u20', a paper
tape. Our implementation maps these devices to disk files, except
for 'u19', which represents the standard output.
As noted above, the MIX computer communicates with the external world
by a set of input-output devices which can be "connected" to it. The
computer interchanges information using blocks of words whose length
depends on the device at hand (*note Devices::). These words are
interpreted by the device either as binary information (for devices
0-16), or as representing printable characters (devices 17-20). In the
last case, each MIX byte is mapped onto a character according to the
following table:
00 01 A 02 B 03 C
04 D 05 E 06 F 07 G
08 H 09 I 10 ~ 11 J
12 K 13 L 14 M 15 N
16 O 17 P 18 Q 19 R
20 [ 21 # 22 S 23 T
24 U 25 V 26 W 27 X
28 Y 29 Z 30 0 31 1
32 2 33 3 34 4 35 5
36 6 37 7 38 8 39 9
40 . 41 , 42 ( 43 )
44 + 45 - 46 * 47 /
48 = 49 $ 50 < 51 >
52 @ 53 ; 54 : 55 '
The value 0 represents a whitespace. The characters '~', '[' and '#'
correspond to symbols not representable as ASCII characters (uppercase
delta, sigma and gamma, respectively), and byte values 56-63 have no
associated character.
Finally, the MIX computer features a virtual CPU which controls the
above components, and which is able to execute a rich set of
instructions (constituting its machine language, similar to those
commonly found in real CPUs), including arithmetic, logical, storing,
comparison and jump instructions. Being a typical von Neumann computer,
the MIX CPU fetches binary instructions from memory sequentially (unless
a jump instruction is found), and stores the address of the next
instruction to be executed in an internal register called "location
counter" (also known as program counter in other architectures).
The next section, *Note MIX instruction set::, gives a complete
description of the available MIX binary instructions.
File: mdk.info, Node: MIX instruction set, Prev: MIX architecture, Up: The MIX computer
2.1.2 MIX instruction set
-------------------------
The following subsections fully describe the instruction set of the MIX
computer. We begin with a description of the structure of binary
instructions and the notation used to refer to their subfields. The
remaining subsections are devoted to describing the actual instructions
available to the MIX programmer.
* Menu:
* Instruction structure::
* Loading operators::
* Storing operators::
* Arithmetic operators::
* Address transfer operators::
* Comparison operators::
* Jump operators::
* Input-output operators::
* Conversion operators::
* Shift operators::
* Miscellaneous operators::
* Execution times::
File: mdk.info, Node: Instruction structure, Next: Loading operators, Prev: MIX instruction set, Up: MIX instruction set
2.1.2.1 Instruction structure
.............................
MIX "instructions" are codified as words with the following subfield
structure:
_Subfield_ _fspec_ _Description_
ADDRESS (0:2) The first two bytes plus sign are the
"address" field. Combined with the INDEX
field, denotes the memory address to be used
by the instruction.
INDEX (3:3) The third byte is the "index", normally used
for indexing the address(1)
(*note Instruction structure-Footnote-1::).
MOD (4:4) Byte four is used either as an operation code
modifier or as a field specification.
OPCODE (5:5) The last (least significant) byte in the word
denotes the operation code.
or, graphically,
------------------------------------------------
| 0 | 1 | 2 | 3 | 4 | 5 |
------------------------------------------------
| ADDRESS | INDEX | MOD | OPCODE |
------------------------------------------------
For a given instruction, 'M' stands for the memory address obtained
after indexing the ADDRESS subfield (using its INDEX byte), and 'V' is
the contents of the subfield indicated by MOD of the memory cell with
address 'M'. For instance, suppose that we have the following contents
of MIX registers and memory cells:
[rI2] = + 00 63
[31] = - 10 11 00 11 22
where '[n]' denotes the contents of the nth memory cell and '[rI2]' the
contents of register 'rI2'(2) (*note Instruction
structure-Footnote-2::). Let us consider the binary instruction
'I = - 00 32 02 11 10'. For this instruction we have:
ADDRESS = - 00 32 = -32
INDEX = 02 = 2
MOD = 11 = (1:3)
OPCODE = 10
M = ADDRESS + [rI2] = -32 + 63 = 31
V = [M](MOD) = (- 10 11 00 11 22)(1:3) = + 00 00 10 11 00
Note that, when computing 'V' using a word and an fspec, we apply a
left padding to the bytes selected by 'MOD' to obtain a complete word as
the result.
In the following subsections, we will assign to each MIX instruction
a mnemonic, or symbolic name. For instance, the mnemonic of 'OPCODE' 10
is 'LD2'. Thus we can rewrite the above instruction as
LD2 -32,2(1:3)
or, for a generic instruction:
MNEMONIC ADDRESS,INDEX(MOD)
Some instructions are identified by both the OPCODE and the MOD fields.
In these cases, the MOD will not appear in the above symbolic
representation. Also when ADDRESS or INDEX are zero, they can be
omitted. Finally, MOD defaults to (0:5) (meaning the whole word).
File: mdk.info, Node: Instruction structure-Footnotes, Up: Instruction structure
(1) The actual memory address the instruction refers to, is obtained
by adding to ADDRESS the value of the 'rI' register denoted by INDEX.
(2) In general, '[X]' will denote the contents of entity 'X'; thus,
by definition, 'V = [M](MOD)'.
File: mdk.info, Node: Loading operators, Next: Storing operators, Prev: Instruction structure, Up: MIX instruction set
2.1.2.2 Loading operators
.........................
The following instructions are used to load memory contents into a
register.
'LDA'
Put in rA the contents of cell no. M. OPCODE = 8, MOD = fspec.
'rA <- V'.
'LDX'
Put in rX the contents of cell no. M. OPCODE = 15, MOD = fspec.
'rX <- V'.
'LDi'
Put in rIi the contents of cell no. M. OPCODE = 8 + i, MOD =
fspec. 'rIi <- V'.
'LDAN'
Put in rA the contents of cell no. M, with opposite sign. OPCODE
= 16, MOD = fspec. 'rA <- -V'.
'LDXN'
Put in rX the contents of cell no. M, with opposite sign. OPCODE
= 23, MOD = fspec. 'rX <- -V'.
'LDiN'
Put in rIi the contents of cell no. M, with opposite sign. OPCODE
= 16 + i, MOD = fspec. 'rIi <- -V'.
In all the above load instructions the 'MOD' field selects the bytes
of the memory cell with address 'M' which are loaded into the requisite
register (indicated by the 'OPCODE'). For instance, the word
'+ 00 13 01 27 11' represents the instruction
LD3 13,1(3:3)
^ ^ ^ ^
| | | |
| | | --- MOD = 27 = 3*8 + 3
| | --- INDEX = 1
| --- ADDRESS = 00 13
--- OPCODE = 11
Let us suppose that, prior to this instruction execution, the state
of the MIX computer is the following:
[rI1] = - 00 01
[rI3] = + 24 12
[12] = - 01 02 03 04 05
As, in this case, 'M = 13 + [rI1] = 12', we have
V = [M](3:3) = (- 01 02 03 04 05)(3:3)
= + 00 00 00 00 03
(note that the specified subfield is left-padded with null bytes to
complete a word). Hence, the MIX state, after the instruction
execution, will be
[rI1] = - 00 01
[rI3] = + 00 03
[12] = - 01 02 03 04 05
To further illustrate loading operators, the following table shows
the contents of 'rX' after different 'LDX' instructions:
'LDX 12(0:0) [rX] = - 00 00 00 00 00'
'LDX 12(0:1) [rX] = - 00 00 00 00 01'
'LDX 12(3:5) [rX] = + 00 00 03 04 05'
'LDX 12(3:4) [rX] = + 00 00 00 03 04'
'LDX 12(0:5) [rX] = - 01 02 03 04 05'
File: mdk.info, Node: Storing operators, Next: Arithmetic operators, Prev: Loading operators, Up: MIX instruction set
2.1.2.3 Storing operators
.........................
The following instructions are the inverse of the load operations: they
are used to store a subfield of a register into a memory location.
Here, MOD represents the subfield of the memory cell that is to be
overwritten with bytes from a register. These bytes are taken beginning
by the rightmost side of the register.
'STA'
Store rA. OPCODE = 24, MOD = fspec. 'V <- rA'.
'STX'
Store rX. OPCODE = 31, MOD = fspec. 'V <- rX'.
'STi'
Store rIi. OPCODE = 24 + i, MOD = fspec. 'V <- rIi'.
'STJ'
Store rJ. OPCODE = 32, MOD = fspec. 'V <- rJ'.
'STZ'
Store zero. OPCODE = 33, MOD = fspec. 'V <- 0'.
By way of example, consider the instruction 'STA 1200(2:3)'. It
causes the MIX to fetch bytes no. 4 and 5 of register A and copy them
to bytes 2 and 3 of memory cell no. 1200 (remember that, for these
instructions, MOD specifies a subfield of _the memory address_). The
other bytes of the memory cell retain their values. Thus, if prior to
the instruction execution we have
[1200] = - 20 21 22 23 24
[rA] = + 01 02 03 04 05
we will end up with
[1200] = - 20 04 05 23 24
[rA] = + 01 02 03 04 05
As a second example, 'ST2 1000(0)' will set the sign of '[1000]' to
that of '[rI2]'.
File: mdk.info, Node: Arithmetic operators, Next: Address transfer operators, Prev: Storing operators, Up: MIX instruction set
2.1.2.4 Arithmetic operators
............................
The following instructions perform arithmetic operations between rA and
rX register and memory contents.
'ADD'
Add and set OV if overflow. OPCODE = 1, MOD = fspec.
'rA <- rA +V'.
'SUB'
Sub and set OV if overflow. OPCODE = 2, MOD = fspec.
'rA <- rA - V'.
'MUL'
Multiply V times rA and store the 10-bytes product in rAX. OPCODE =
3, MOD = fspec. 'rAX <- rA x V'.
'DIV'
rAX is considered a 10-bytes number, and it is divided by V. OPCODE
= 4, MOD = fspec. 'rA <- rAX / V', 'rX' <- reminder.
In all the above instructions, '[rA]' is one of the operands of the
binary arithmetic operation, the other being 'V' (that is, the specified
subfield of the memory cell with address 'M'), padded with zero bytes on
its left-side to complete a word. In multiplication and division, the
register 'X' comes into play as a right-extension of the register 'A',
so that we are able to handle 10-byte numbers whose more significant
bytes are those of 'rA' (the sign of this 10-byte number is that of
'rA': 'rX''s sign is ignored).
Addition and subtraction of MIX words can give rise to overflows,
since the result is stored in a register with room to only 5 bytes (plus
sign). When this occurs, the operation result modulo 1,073,741,823 (the
maximum value storable in a MIX word) is stored in 'rA', and the
overflow toggle is set to TRUE.
File: mdk.info, Node: Address transfer operators, Next: Comparison operators, Prev: Arithmetic operators, Up: MIX instruction set
2.1.2.5 Address transfer operators
..................................
In these instructions, 'M' (the address of the instruction after
indexing) is used as a number instead of as the address of a memory
cell. Consequently, 'M' can have any valid word value (i.e., it's not
limited to the 0-3999 range of a memory address).
'ENTA'
Enter 'M' in [rA]. OPCODE = 48, MOD = 2. 'rA <- M'.
'ENTX'
Enter 'M' in [rX]. OPCODE = 55, MOD = 2. 'rX <- M'.
'ENTi'
Enter 'M' in [rIi]. OPCODE = 48 + i, MOD = 2. 'rIi <- M'.
'ENNA'
Enter '-M' in [rA]. OPCODE = 48, MOD = 3. 'rA <- -M'.
'ENNX'
Enter '-M' in [rX]. OPCODE = 55, MOD = 3. 'rX <- -M'.
'ENNi'
Enter '-M' in [rIi]. OPCODE = 48 + i, MOD = 3. 'rIi <- -M'.
'INCA'
Increase [rA] by 'M'. OPCODE = 48, MOD = 0. 'rA <- rA + M'.
'INCX'
Increase [rX] by 'M'. OPCODE = 55, MOD = 0. 'rX <- rX + M'.
'INCi'
Increase [rIi] by 'M'. OPCODE = 48 + i, MOD = 0. 'rIi <- rIi +
M'.
'DECA'
Decrease [rA] by 'M'. OPCODE = 48, MOD = 1. 'rA <- rA - M'.
'DECX'
Decrease [rX] by 'M'. OPCODE = 55, MOD = 1. 'rX <- rX - M'.
'DECi'
Decrease [rIi] by 'M'. OPCODE = 48 + i, MaOD = 0. 'rIi <- rIi -
M'.
In the above instructions, the subfield 'ADDRESS' acts as an
immediate (indexed) operand, and allow us to set directly the contents
of the MIX registers without an indirection to the memory cells (in a
real CPU this would mean that they are faster that the previously
discussed instructions, whose operands are fetched from memory). So, if
you want to store in 'rA' the value -2000 (- 00 00 00 31 16), you can
use the binary instruction + 31 16 00 03 48, or, symbolically,
ENNA 2000
Used in conjunction with the store operations ('STA', 'STX', etc.),
these instructions also allow you to set memory cells contents to
concrete values.
Note that in these address transfer operators, the 'MOD' field is not
a subfield specificator, but serves to define (together with 'OPCODE')
the concrete operation to be performed.
File: mdk.info, Node: Comparison operators, Next: Jump operators, Prev: Address transfer operators, Up: MIX instruction set
2.1.2.6 Comparison operators
............................
So far, we have learned how to move values around between the MIX
registers and its memory cells, and also how to perform arithmetic
operations using these values. But, in order to write non-trivial
programs, other functionalities are needed. One of the most common is
the ability to compare two values, which, combined with jumps, will
allow the execution of conditional statements. The following
instructions compare the value of a register with 'V', and set the CM
indicator to the result of the comparison (i.e. to 'E', 'G' or 'L',
equal, greater or lesser respectively).
'CMPA'
Compare [rA] with V. OPCODE = 56, MOD = fspec.
'CMPX'
Compare [rX] with V. OPCODE = 63, MOD = fspec.
'CMPi'
Compare [rIi] with V. OPCODE = 56 + i, MOD = fspec.
As explained above, these instructions modify the value of the MIX
comparison indicator; but maybe you are asking yourself how do you use
this value: enter jump operators, in the next subsection.
File: mdk.info, Node: Jump operators, Next: Input-output operators, Prev: Comparison operators, Up: MIX instruction set
2.1.2.7 Jump operators
......................
The MIX computer has an internal register, called the "location
counter", which stores the address of the next instruction to be fetched
and executed by the virtual CPU. You cannot directly modify the contents
of this internal register with a load instruction: after fetching the
current instruction from memory, it is automatically increased in one
unit by the MIX. However, there is a set of instructions (which we call
jump instructions) which can alter the contents of the location counter
provided some condition is met. When this occurs, the value of the next
instruction address that would have been fetched in the absence of the
jump is stored in 'rJ' (except for 'JSJ'), and the location counter is
set to the value of 'M' (so that the next instruction is fetched from
this new address). Later on, you can return to the point when the jump
occurred reading the address stored in 'rJ'.
The MIX computer provides the following jump instructions: With these
instructions you force a jump to the specified address. Use 'JSJ' if
you do not care about the return address.
'JMP'
Unconditional jump. OPCODE = 39, MOD = 0.
'JSJ'
Unconditional jump, but rJ is not modified. OPCODE = 39, MOD = 1.
These instructions check the overflow toggle to decide whether to
jump or not.
'JOV'
Jump if OV is set (and turn it off). OPCODE = 39, MOD = 2.
'JNOV'
Jump if OV is not set (and turn it off). OPCODE = 39, MOD = 3.
In the following instructions, the jump is conditioned to the
contents of the comparison flag:
'JL'
Jump if '[CM] = L'. OPCODE = 39, MOD = 4.
'JE'
Jump if '[CM] = E'. OPCODE = 39, MOD = 5.
'JG'
Jump if '[CM] = G'. OPCODE = 39, MOD = 6.
'JGE'
Jump if '[CM]' does not equal 'L'. OPCODE = 39, MOD = 7.
'JNE'
Jump if '[CM]' does not equal 'E'. OPCODE = 39, MOD = 8.
'JLE'
Jump if '[CM]' does not equal 'G'. OPCODE = 39, MOD = 9.
You can also jump conditioned to the value stored in the MIX
registers, using the following instructions:
'JAN'
'JAZ'
'JAP'
'JANN'
'JANZ'
'JANP'
'JAE'
'JAO'
Jump if the content of rA is, respectively, negative, zero,
positive, non-negative, non-zero, non-positive, even or odd.
OPCODE = 40, MOD = 0, 1, 2, 3, 4, 5, 6, 7.
'JXN'
'JXZ'
'JXP'
'JXNN'
'JXNZ'
'JXNP'
'JXE'
'JXO'
Jump if the content of rX is, respectively, negative, zero,
positive, non-negative, non-zero, non-positive, even or odd.
OPCODE = 47, MOD = 0, 1, 2, 3, 4, 5, 6, 7.
'JiN'
'JiZ'
'JiP'
'JiNN'
'JiNZ'
'JiNP'
Jump if the content of rIi is, respectively, negative, zero,
positive, non-negative, non-zero or non-positive. OPCODE = 40 + i,
MOD = 0, 1, 2, 3, 4, 5.
File: mdk.info, Node: Input-output operators, Next: Conversion operators, Prev: Jump operators, Up: MIX instruction set
2.1.2.8 Input-output operators
..............................
As explained in previous sections (*note MIX architecture::), the MIX
computer can interact with a series of block devices. To that end, you
have at your disposal the following instructions:
'IN'
Transfer a block of words from the specified unit to memory,
starting at address M. OPCODE = 36, MOD = I/O unit.
'OUT'
Transfer a block of words from memory (starting at address M) to
the specified unit. OPCODE = 37, MOD = I/O unit.
'IOC'
Perform a control operation (given by M) on the specified unit.
OPCODE = 35, MOD = I/O unit.
'JRED'
Jump to M if the specified unit is ready. OPCODE = 38, MOD = I/O
unit.
'JBUS'
Jump to M if the specified unit is busy. OPCODE = 34, MOD = I/O
unit.
In all the above instructions, the 'MOD' subfile must be in the range
0-20, since it denotes the operation's target device. The 'IOC'
instruction makes sense for magnetic tape devices ('MOD' = 0-7): it
shifts the read/write pointer by the number of blocks given by 'M' (if
it equals zero, the tape is rewound), paper tape devices ('MOD' = 20):
'M' should be 0, the tape is rewound, and disk/drum devices ('MOD' =
8-15): it moves the read/write pointer to the block specified in rX and
'M' should be 0(1) (*note Input-output operators-Footnote-1::).
File: mdk.info, Node: Input-output operators-Footnotes, Up: Input-output operators
(1) In Knuth's original definition, there are other control
operations available, but they do not make sense when implementing the
devices as disk files (as we do in MDK simulator). For the same reason,
MDK devices are always ready, since all input-output operations are
performed using synchronous system calls.
File: mdk.info, Node: Conversion operators, Next: Shift operators, Prev: Input-output operators, Up: MIX instruction set
2.1.2.9 Conversion operators
............................
The following instructions convert between numerical values and their
character representations.
'NUM'
Convert rAX, assumed to contain a character representation of a
number, to its numerical value and store it in rA. OPCODE = 5, MOD
= 0.
'CHAR'
Convert the number stored in rA to a character representation and
store it in rAX. OPCODE = 5, MOD = 1.
Digits are represented in MIX by the range of values 30-39 (digits 0-9).
Thus, if the contents of 'rA' and 'rX' are, for instance,
[rA] = + 30 30 31 32 33
[rX] = + 31 35 39 30 34
the represented number is 0012315904, and 'NUM' will store this value in
'rA' (i.e., we end up with '[rA]' = + 0 46 62 52 0 = 12315904).
If any byte in 'rA' or 'rB' does not belong to the range 30-39, it is
interpreted by 'NUM' as the digit obtained by taking its value modulo
10. E.g. values 0, 10, 20, 30, 40, 50, 60 all represent the digit 0;
2, 12, 22, etc. represent the digit 2, and so on. For instance, the
number 0012315904 mentioned above could also be represented as
[rA] = + 10 40 31 52 23
[rX] = + 11 35 49 20 54
'CHAR' performs the inverse operation, using only the values 30 to 39
for representing digits 0-9.
File: mdk.info, Node: Shift operators, Next: Miscellaneous operators, Prev: Conversion operators, Up: MIX instruction set
2.1.2.10 Shift operators
........................
The following instructions perform byte-wise shifts of the contents of
'rA' and 'rX'.
'SLA'
'SRA'
'SLAX'
'SRAX'
'SLC'
'SRC'
Shift rA or rAX left, right, or rAX circularly (see example below)
left or right. M specifies the number of bytes to be shifted.
OPCODE = 6, MOD = 0, 1, 2, 3, 4, 5.
The following instructions perform binary shifts of the contents of 'rA'
and 'rX'.
'SLB'
'SRB'
Shift rAX left or right binary. M specifies the number of binary
places to shift. OPCODE = 6, MOD = 6, 7
If we begin with, say, '[rA]' = - 01 02 03 04 05, we would have the
following modifications to 'rA' contents when performing the
instructions on the left column:
SLA 2 [rA] = - 03 04 05 00 00
SLA 6 [rA] = - 00 00 00 00 00
SRA 1 [rA] = - 00 01 02 03 04
Note that the sign is unaffected by shift operations. On the other
hand, 'SLC', 'SRC', 'SLAX', 'SRAX', 'SLB' and 'SRB' treat 'rA' and 'rX'
as a single 10-bytes register (ignoring again the signs). For instance,
if we begin with '[rA]' = + 01 02 03 04 05 and '[rX]' =
- 06 07 08 09 10, we would have:
SLC 3 [rA] = + 04 05 06 07 08 [rX] = - 09 10 01 02 03
SLAX 3 [rA] = + 04 05 06 07 08 [rX] = - 09 10 00 00 00
SRC 4 [rA] = + 07 08 09 10 01 [rX] = - 02 03 04 05 06
SRAX 4 [rA] = + 00 00 00 00 01 [rX] = - 02 03 04 05 06
SLB 1 [rA] = + 02 04 06 08 10 [rX] = - 12 14 16 18 20
File: mdk.info, Node: Miscellaneous operators, Next: Execution times, Prev: Shift operators, Up: MIX instruction set
2.1.2.11 Miscellaneous operators
................................
Finally, we list in the following table three miscellaneous MIX
instructions which do not fit in any of the previous subsections:
'MOVE'
Move MOD words from M to the location stored in rI1. OPCODE = 7,
MOD = no. of words.
'NOP'
No operation. OPCODE = 0, MOD = 0.
'HLT'
Halt. Stops instruction fetching. OPCODE = 5, MOD = 2.
The only effect of executing 'NOP' is increasing the location counter,
while 'HLT' usually marks program termination.
File: mdk.info, Node: Execution times, Prev: Miscellaneous operators, Up: MIX instruction set
2.1.2.12 Execution times
........................
When writing MIXAL programs (or any kind of programs, for that matter),
we shall often be interested in their execution time. Loosely speaking,
we will be interested in the answer to the question: how long does it
take a program to execute? Of course, this execution time will be a
function of the input size, and the answer to our question is commonly
given as the asymptotic behaviour as a function of the input size. At
any rate, to compute this asymptotic behaviour, we need a measure of how
long execution of a single instruction takes in our (virtual) CPU.
Therefore, each MIX instruction will have an associated execution time,
given in arbitrary units (in a real computer, the value of this unit
will depend on the hardware configuration). When our MIX virtual
machine executes programs, it will (optionally) give you the value of
their execution time based upon the execution time of each single
instruction.
In the following table, the execution times (in the above mentioned
arbitrary units) of the MIX instructions are given.
'NOP' 1 'ADD' 2 'SUB' 2 'MUL' 10
'DIV' 12 'NUM' 10 'CHAR' 10 'HLT' 10
'SLx' 2 'SRx' 2 'LDx' 2 'STx' 2
'JBUS' 1 'IOC' 1 'IN' 1 'OUT' 1
'JRED' 1 'Jx' 1 'INCx' 1 'DECx' 1
'ENTx' 1 'ENNx' 1 'CMPx' 1 'MOVE' 1+2F
In the above table, 'F' stands for the number of blocks to be moved
(given by the 'FSPEC' subfield of the instruction); 'SLx' and 'SRx' are
a short cut for the byte-shifting operations; 'LDx' denote all the
loading operations; 'STx' are the storing operations; 'Jx' stands for
all the jump operations, and so on with the rest of abbreviations.
File: mdk.info, Node: MIXAL, Prev: The MIX computer, Up: MIX and MIXAL tutorial
2.2 MIXAL
=========
In the previous sections we have listed all the available MIX binary
instructions. As we have shown, each instruction is represented by a
word which is fetched from memory and executed by the MIX virtual CPU.
As is the case with real computers, the MIX knows how to decode
instructions in binary format (the so-called machine language), but a
human programmer would have a tough time if she were to write her
programs in machine language. Fortunately, the MIX computer can be
programmed using an assembly language, MIXAL, which provides a symbolic
way of writing the binary instructions understood by the imaginary MIX
computer. If you have used assembler languages before, you will find
MIXAL a very familiar language. MIXAL source files are translated to
machine language by a MIX assembler, which produces a binary file (the
actual MIX program) which can be directly loaded into the MIX memory and
subsequently executed.
In this section, we describe MIXAL, the MIX assembly language. The
implementation of the MIX assembler program and MIX computer simulator
provided by MDK are described later on (*note Getting started::).
* Menu:
* Basic structure:: Writing basic MIXAL programs.
* MIXAL directives:: Assembler directives.
* Expressions:: Evaluation of expressions.
* W-expressions:: Evaluation of w-expressions.
* Local symbols:: Special symbol table entries.
* Literal constants:: Specifying an immediate operand.
File: mdk.info, Node: Basic structure, Next: MIXAL directives, Prev: MIXAL, Up: MIXAL
2.2.1 Basic program structure
-----------------------------
The MIX assembler reads MIXAL files line by line, producing, when
required, a binary instruction, which is associated to a predefined
memory address. To keep track of the current address, the assembler
maintains an internal location counter which is incremented each time an
instruction is compiled. In addition to MIX instructions, you can
include in MIXAL file assembly directives (or pseudoinstructions)
addressed at the assembler itself (for instance, telling it where the
program starts and ends, or to reposition the location counter; see
below).
MIX instructions and assembler directives(1) (*note Basic
structure-Footnote-1::) are written in MIXAL (one per source file line)
according to the following pattern:
[LABEL] MNEMONIC [OPERAND] [COMMENT]
where 'OPERAND' is of the form
[ADDRESS][,INDEX][(MOD)]
Items between square brackets are optional, and
'LABEL'
is an alphanumeric identifier (a "symbol") which gets the current
value of the location counter, and can be used in subsequent
expressions,
'MNEMONIC'
is a literal denoting the operation code of the instruction (e.g.
'LDA', 'STA'; see *note MIX instruction set::) or an assembly
pseudoinstruction (e.g. 'ORIG', 'EQU'),
'ADDRESS'
is an expression evaluating to the address subfield of the
instruction,
'INDEX'
is an expression evaluating to the index subfield of the
instruction, which defaults to 0 (i.e., no use of indexing) and can
only be used when 'ADDRESS' is present,
'MOD'
is an expression evaluating to the mod subfield of the instruction.
Its default value, when omitted, depends on 'OPCODE',
'COMMENT'
any number of spaces after the operand mark the beginning of a
comment, i.e. any text separated by white space from the operand
is ignored by the assembler (note that spaces are not allowed
within the 'OPERAND' field).
Note that spaces are _not_ allowed between the 'ADDRESS', 'INDEX' and
'MOD' fields if they are present. White space is used to separate the
label, operation code and operand parts of the instruction(2) (*note
Basic structure-Footnote-2::).
We have already listed the mnemonics associated with each MIX
instruction; sample MIXAL instructions representing MIX instructions
are:
HERE LDA 2000 HERE represents the current location counter
LDX HERE,2(1:3) this is a comment
JMP 1234
File: mdk.info, Node: Basic structure-Footnotes, Up: Basic structure
(1) We shall call them, collectively, MIXAL instructions.
(2) In fact, Knuth's definition of MIXAL restricts the column number
at which each of these instruction parts must start. The MIXAL
assembler included in MDK, 'mixasm', does not impose such restriction.
File: mdk.info, Node: MIXAL directives, Next: Expressions, Prev: Basic structure, Up: MIXAL
2.2.2 MIXAL directives
----------------------
MIXAL instructions can be either one of the MIX machine instructions
(*note MIX instruction set::) or one of the following assembly
pseudoinstructions:
'ORIG'
Sets the value of the memory address to which following
instructions will be allocated after compilation.
'EQU'
Used to define a symbol's value, e.g. 'SYM EQU 2*200/3'.
'CON'
The value of the given expression is copied directly into the
current memory address.
'ALF'
Takes as operand five characters, constituting the five bytes of a
word which is copied directly into the current memory address.
'END'
Marks the end of the program. Its operand gives the start address
for program execution.
The operand of 'ORIG', 'EQU', 'CON' and 'END' can be any expression
evaluating to a constant MIX word, i.e., either a simple MIXAL
expression (composed of numbers, symbols and binary operators, *note
Expressions::) or a w-expression (*note W-expressions::).
All MIXAL programs must contain an 'END' directive, with a twofold
end: first, it marks the end of the assembler job, and, in the second
place, its (mandatory) operand indicates the start address for the
compiled program (that is, the address at which the virtual MIX machine
must begin fetching instructions after loading the program). It is also
very common (although not mandatory) to include at least an 'ORIG'
directive to mark the initial value of the assembler's location counter
(remember that it stores the address associated with each compiled MIX
instruction). Thus, a minimal MIXAL program would be
ORIG 2000 set the initial compilation address
NOP this instruction will be loaded at address 2000
HLT and this one at address 2001
END 2000 end of program; start at address 2000
this line is not parsed by the assembler
The assembler will generate two binary instructions ('NOP'
(+ 00 00 00 00 00) and 'HLT' (+ 00 00 02 05)), which will be loaded at
addresses 2000 and 2001. Execution of the program will begin at address
2000. Every MIXAL program should also include a 'HLT' instruction,
which will mark the end of program execution (but not of program
compilation).
The 'EQU' directive allows the definition of symbolic names for
specific values. For instance, we could rewrite the above program as
follows:
START EQU 2000
ORIG START
NOP
HLT
END START
which would give rise to the same compiled code. Symbolic constants (or
symbols, for short) can also be implicitly defined placing them in the
'LABEL' field of a MIXAL instruction: in this case, the assembler
assigns to the symbol the value of the location counter before compiling
the line. Hence, a third way of writing our trivial program is
ORIG 2000
START NOP
HLT
END START
The 'CON' directive allows you to directly specify the contents of
the memory address pointed by the location counter. For instance, when
the assembler encounters the following code snippet
ORIG 1150
CON -1823473
it will assign to the memory cell number 1150 the contents
- 00 06 61 11 49 (which corresponds to the decimal value -1823473).
Finally, the 'ALF' directive lets you specify the memory contents as
a set of five (optionally quoted) characters, which are translated by
the assembler to their byte values, conforming in that way the binary
word that is to be stored in the corresponding memory cell. This
directive comes in handy when you need to store printable messages in a
memory address, as in the following example (1) (*note MIXAL
directives-Footnote-1::):
OUT MSG MSG is not yet defined here (future reference)
MSG ALF "THIS " MSG gets defined here
ALF "IS A "
ALF "MESSA"
ALF "GE. "
The above snippet also shows the use of a "future reference", that is,
the usage of a symbol ('MSG' in the example) prior of its actual
definition. The MIXAL assembler is able to handle future references
subject to some limitations which are described in the following section
(*note Expressions::).
Any line starting with an asterisk is treated as a comment and
ignored by the assembler.
* This is a comment: this line is ignored.
* This line is an error: * must be in column 1.
As noted in the previous section, comments can also be located after
the 'OPERAND' field of an instruction, separated from it by white space,
as in
LABEL LDA 100 This is also a comment
File: mdk.info, Node: MIXAL directives-Footnotes, Up: MIXAL directives
(1) In the original MIXAL definition, the 'ALF' argument is not
quoted. You can write the operand (as the 'ADDRESS' field) without
quotes, but, in this case, you must follow the alignment rules of the
original MIXAL definition (namely, the 'ADDRESS' must start at column
17).
File: mdk.info, Node: Expressions, Next: W-expressions, Prev: MIXAL directives, Up: MIXAL
2.2.3 Expressions
-----------------
The 'ADDRESS', 'INDEX' and 'MOD' fields of a MIXAL instruction can be
expressions, formed by numbers, identifiers and binary operators ('+ - *
/ // :'). '+' and '-' can also be used as unary operators. Operator
precedence is from left to right: there is no other operator precedence
rule, and parentheses cannot be used for grouping. A stand-alone
asterisk denotes the current memory location; thus, for instance,
4+2**
evaluates to 6 (4 plus 2) times the current memory location. White
space is not allowed within expressions.
The special binary operator ':' has the same meaning as in fspecs,
i.e.,
A:B = 8*A + B
while 'A//B' stands for the quotient of the ten-byte number
'A' 00 00 00 00 00 (that is, A right-padded with 5 null bytes or, what
amounts to the same, multiplied by 64 to the fifth power) divided by
'B'. Sample expressions are:
18-8*3 = 30
14/3 = 4
1+3:11 = 4:11 = 43
1//64 = (01 00 00 00 00 00)/(00 00 00 01 00) = (01 00 00 00 00)
Note that all MIXAL expressions evaluate to a MIX word (by definition).
All symbols appearing within an expression must be previously
defined. Future references are only allowed when appearing standalone
(or modified by an unary operator) in the 'ADDRESS' part of a MIXAL
instruction, e.g.
* OK: stand alone future reference
STA -S1(1:5)
* ERROR: future reference in expression
LDX 2-S1
S1 LD1 2000
File: mdk.info, Node: W-expressions, Next: Local symbols, Prev: Expressions, Up: MIXAL
2.2.4 W-expressions
-------------------
Besides expressions, as described above (*note Expressions::), the MIXAL
assembler is able to handle the so called "w-expressions" as the
operands of the directives 'ORIG', 'EQU', 'CON' and 'END' (*note MIXAL
directives::). The general form of a w-expression is the following:
WEXP = EXP[(EXP)][,WEXP]
where 'EXP' stands for an expression and square brackets denote optional
items. Thus, a w-expression is made by an expression, followed by an
optional expression between parenthesis, followed by any number of
similar constructs separated by commas. Sample w-expressions are:
2000
235(3)
S1+3(S2),3000
S1,S2(3:5),23
W-expressions are evaluated from left to right as follows:
* Start with an accumulated result 'w' equal to 0.
* Take the first expression of the comma-separated list and evaluate
it. For instance, if the w-expression is 'S1+2(2:4),2000(S2)', we
evaluate first 'S1+2'; let's suppose that 'S1' equals 265230: then
'S1+2 = 265232 = + 00 01 00 48 16'.
* Evaluate the expression within parenthesis, reducing it to an
f-spec of the form 'L:R'. In our previous example, the expression
between parenthesis already has the desired form: 2:4.
* Substitute the bytes of the accumulated result 'w' designated by
the f-spec using those of the previous expression value. In our
sample, 'w = + 00 00 00 00 00', and we must substitute bytes 2, 3
and 4 of 'w' using values from 265232. We need 3 bytes, and we
take the least significant ones: 00, 48, and 16, and insert them in
positions 2, 3 and 4 of 'w', obtaining 'w = + 00 00 48 16 00'.
* Repeat this operation with the remaining terms, acting on the new
value of 'w'. In our example, if, say, 'S2 = 1:1', we must
substitute the first byte of 'w' using one byte (the least
significant) from 2000, that is, 16 (since 2000 = + 00 00 00 31 16)
and, therefore, we obtain 'w = + 16 00 48 16 00'; summing up, we
have obtained '265232(1:4),2000(1:1) = + 16 00 48 16 00 =
268633088'.
As a second example, in the w-expression
1(1:2),66(4:5)
we first take two bytes from 1 (00 and 01) and store them as bytes 1 and
2 of the result (obtaining '+ 00 01 00 00 00') and, afterwards, take two
bytes from 66 (01 and 02) and store them as bytes 4 and 5 of the result,
obtaining '+ 00 01 00 01 02' (262210). The process is repeated for each
new comma-separated example. For instance:
1(1:1),2(2:2),3(3:3),4(4:4) = 01 02 03 04 00
As stated before, w-expressions can only appear as the operands of
MIXAL directives taking a constant value ('ORIG', 'EQU', 'CON' and
'END'). Future references are _not_ allowed within w-expressions (i.e.,
all symbols appearing in a w-expression must be defined before it is
used).
File: mdk.info, Node: Local symbols, Next: Literal constants, Prev: W-expressions, Up: MIXAL
2.2.5 Local symbols
-------------------
Besides user defined symbols, MIXAL programmers can use the so called
"local symbols", which are symbols of the form '[1-9][HBF]'. A local
symbol 'nB' refers to the address of the last previous occurrence of
'nH' as a label, while 'nF' refers to the next 'nH' occurrence. Unlike
user defined symbols, 'nH' can appear multiple times in the 'LABEL' part
of different MIXAL instructions. The following code shows an instance
of local symbols' usage:
* line 1
1H LDA 100
* line 2: 1B refers to address of line 1, 3F refers to address of line 4
STA 3F,2(1B//2)
* line 3: redefinition of 1H
1H STZ
* line 4: 1B refers to address of line 3
3H JMP 1B
Note that a 'B' local symbol never refers to a definition in its own
line, that is, in the following program:
ORIG 1999
ST NOP
3H EQU 69
3H ENTA 3B local symbol 3B refers to 3H in previous line
HLT
END ST
the contents of 'rA' is set to 69 and _not_ to 2001. An specially
tricky case occurs when using local symbols in conjunction with 'ORIG'
pseudoinstructions. To wit(1) (*note Local symbols-Footnote-1::),
ORIG 1999
ST NOP
3H CON 10
ENT1 *
LDA 3B
** rI1 is 2001, rA is 10. So far so good!
3H ORIG 3B+1000
** at this point 3H equals 2003
** and the location counter equals 3000.
ENT2 *
LDX 3B
** rI2 contains 3000, rX contains 2003.
HLT
END ST
File: mdk.info, Node: Local symbols-Footnotes, Up: Local symbols
(1) The author wants to thank Philip E. King for pointing these two
special cases of local symbol usage to him.
File: mdk.info, Node: Literal constants, Prev: Local symbols, Up: MIXAL
2.2.6 Literal constants
-----------------------
MIXAL allows the introduction of "literal constants", which are
automatically stored in memory addresses after the end of the program by
the assembler. Literal constants are denoted as '=wexp=', where 'wexp'
is a w-expression (*note W-expressions::). For instance, the code
L EQU 5
LDA =20-L=
causes the assembler to add after the program's end an instruction
with contents 15 ('20-L'), and to assemble the above code as the
instruction ' LDA a', where 'a' stands for the address in which the
value 15 is stored. In other words, the compiled code is equivalent to
the following:
L EQU 5
LDA a
...
a CON 20-L
END start
File: mdk.info, Node: Getting started, Next: Emacs tools, Prev: MIX and MIXAL tutorial, Up: Top
3 Getting started
*****************
In this chapter, you will find a sample code-compile-run-debug session
using the MDK utilities. Familiarity with the MIX mythical computer and
its assembly language MIXAL (as described in Knuth's TAOCP) is assumed;
for a compact reminder, see *note MIX and MIXAL tutorial::.
* Menu:
* Writing a source file:: A sample MIXAL source file.
* Compiling:: Using 'mixasm' to compile source
files into binary format.
* Running the program:: Running and debugging your programs.
* Using mixguile:: Using the Scheme interpreter to run and
debug your programs.
* Using Scheme in mixvm and gmixvm::
File: mdk.info, Node: Writing a source file, Next: Compiling, Prev: Getting started, Up: Getting started
3.1 Writing a source file
=========================
MIXAL programs can be written as ASCII files with your editor of choice.
Here you have the mandatory _hello world_ as written in the MIXAL
assembly language:
* (1)
* hello.mixal: say 'hello world' in MIXAL (2)
* (3)
* label ins operand comment (4)
TERM EQU 19 the MIX console device number (5)
ORIG 3000 start address (6)
START OUT MSG(TERM) output data at address MSG (7)
HLT halt execution (8)
MSG ALF "MIXAL" (9)
ALF " HELL" (10)
ALF "O WOR" (11)
ALF "LD " (12)
END START end of the program (13)
MIXAL source files should have the extension '.mixal' when used with the
MDK utilities. As you can see in the above sample, each line in a MIXAL
file can be divided into four fields separated by an arbitrary amount of
whitespace characters (blanks and or tabs). While in Knuth's definition
of MIXAL each field must start at a fixed pre-defined column number, the
MDK assembler loosens this requirement and lets you format the file as
you see fit. The only restrictions retained are for comment lines (like
1-4) which must begin with an asterisk (*) placed at column 1, and for
the label field (see below) which, if present, must also start at column
1. The four fields in each non-comment line are:
- an optional label, which either refers to the current memory
address (as 'START' and 'MSG' in lines 7 and 9) or a defined symbol
('TERM') (if present, the label must always start at the first
column in its line, for the first whitespace in the line marks the
beginning of the second field),
- an operation mnemonic, which can represent either a MIX instruction
('OUT' and 'HLT' in lines 7 and 8 above), or an assembly
pseudoinstruction (e.g., the 'ORIG' pseudoinstruction in line 6(1)
(*note Writing a source file-Footnote-1::).
- an optional operand for the (pseudo)instruction, and
- an optional free text comment.
Lines 9-12 of the 'hello.mixal' file above also show the second (and
last) difference between Knuth's MIXAL definition and ours: the operand
of the 'ALF' pseudoinstruction (a word of five characters) must be
quoted using ""(2) (*note Writing a source file-Footnote-2::).
The workings of this sample program should be straightforward if you
are familiar with MIXAL. See TAOCP vol. 1 for a thorough definition or
*note MIX and MIXAL tutorial::, for a tutorial.
File: mdk.info, Node: Writing a source file-Footnotes, Up: Writing a source file
(1) If an 'ORIG' directive is not used, the program will be loaded by
the virtual machine at address 0. 'ORIG' allows allocating the
executable code where you see fit.
(2) In Knuth's definition, the operand always starts at a fixed
column number, and the use of quotation is therefore unnecessary. As
'mixasm' releases this requirement, marking the beginning and end of the
'ALF' operand disambiguates the parser's recognition of this operand
when it includes blanks. Note that double-quotes (") are not part of
the MIX character set, and, therefore, no escape characters are needed
within 'ALF''s operands.
File: mdk.info, Node: Compiling, Next: Running the program, Prev: Writing a source file, Up: Getting started
3.2 Compiling
=============
Three simulators of the MIX computer, called 'mixvm', 'gmixvm' and
'mixguile', are included in the MDK tools. They are able to run binary
files containing MIX instructions written in their binary
representation. You can translate MIXAL source files into this binary
form using 'mixasm', the MIXAL assembler. So, in order to compile the
'hello.mixal' file, you can type the following command at your shell
prompt:
mixasm hello <RET>
If the source file contains no errors, this will produce a binary
file called 'hello.mix' which can be loaded and run by the MIX virtual
machine. Unless the 'mixasm' option '-O' is provided, the assembler
will include debug information in the executable file (for a complete
description of all the compilation options, see *note mixasm::). Now,
your are ready to run your first MIX program, as described in the
following section.
File: mdk.info, Node: Running the program, Next: Using mixguile, Prev: Compiling, Up: Getting started
3.3 Running the program
=======================
MIX is a mythical computer, so it is no use ordering it from your
favorite hardware provider. MDK provides three software simulators of
the computer, though. They are
* 'mixvm', a command line oriented simulator,
* 'gmixvm', a GTK based graphical interface to 'mixvm', and
* 'mixguile', a Guile shell with a built-in MIX simulator.
All three simulators accept the same set of user commands, but offer
a different user interface, as noted above. In this section we shall
describe some of these commands, and show you how to use them from
'mixvm''s command line. You can use them as well at 'gmixvm''s command
prompt (*note gmixvm::), or using the built-in Scheme primitives of
'mixguile' (*note Using mixguile::).
Using the MIX simulators, you can run your MIXAL programs, after
compiling them with 'mixasm' into binary '.mix' files. 'mixvm' can be
used either in "interactive" or "non-interactive" mode. In the second
case, 'mixvm' will load your program into memory, execute it (producing
any output due to MIXAL 'OUT' instructions present in the program), and
exit when it encounters a 'HLT' instruction. In interactive mode, you
will enter a shell prompt which allows you issuing commands to the
running virtual machine. These commands will permit you to load, run
and debug programs, as well as to inspect the MIX computer state
(register contents, memory cells contents and so on).
* Menu:
* Non-interactive mode:: Running your programs non-interactively.
* Interactive mode:: Running programs interactively.
* Debugging:: Commands for debugging your programs.
File: mdk.info, Node: Non-interactive mode, Next: Interactive mode, Prev: Running the program, Up: Running the program
3.3.1 Non-interactive mode
--------------------------
To make 'mixvm' work in non-interactive mode, use the '-r' flag. Thus,
to run our 'hello.mix' program, simply type
mixvm -r hello <RET>
at your command prompt, and you will get the following output:
MIXAL HELLO WORLD
Since our hello world program uses MIX's device number 19 as its output
device (*note Writing a source file::), the output is redirected to the
shell's standard output. Had you used any other MIX output devices
(disks, drums, line printer, etc.), 'mixvm' would have created a file
named after the device used (e.g. 'disk4.dev') and written its output
there(1) (*note Non-interactive mode-Footnote-1::).
The virtual machine can also report the execution time of the
program, according to the (virtual) time spent in each of the binary
instructions (*note Execution times::). Printing of execution time
statistics is activated with the '-t' flag; running
mixvm -t -r hello <RET>
produces the following output:
MIXAL HELLO WORLD
** Execution time: 11
Sometimes, you will prefer to store the results of your program in
MIX registers rather than writing them to a device. In such cases,
'mixvm''s '-d' flag is your friend: it makes 'mixvm' dump the contents
of its registers and flags after executing the loaded program. For
instance, typing the following command at your shell's prompt
mixvm -d -r hello
you will obtain the following output:
MIXAL HELLO WORLD
rA: + 00 00 00 00 00 (0000000000)
rX: + 00 00 00 00 00 (0000000000)
rJ: + 00 00 (0000)
rI1: + 00 00 (0000) rI2: + 00 00 (0000)
rI3: + 00 00 (0000) rI4: + 00 00 (0000)
rI5: + 00 00 (0000) rI6: + 00 00 (0000)
Overflow: F
Cmp: E
which, in addition to the program's outputs and execution time, gives
you the contents of the MIX registers and the values of the overflow
toggle and comparison flag (admittedly, rather uninteresting in our
sample).
As you can see, running programs non-interactively has many
limitations. You cannot peek the virtual machine's memory contents, not
to mention stepping through your program's instructions or setting
breakpoints(2) (*note Non-interactive mode-Footnote-2::). Enter
interactive mode.
File: mdk.info, Node: Non-interactive mode-Footnotes, Up: Non-interactive mode
(1) The device files are stored, by default, in a directory called
'.mdk', which is created in your home directory the first time 'mixvm'
is run. You can change this default directory using the command
'devdir' when running 'mixvm' in interactive mode (*note Configuration
commands::)
(2) The 'mixguile' program allows you to execute arbitrary
combinations of 'mixvm' commands (using Scheme) non-interactively.
*Note Scheme scripts::.
File: mdk.info, Node: Interactive mode, Next: Debugging, Prev: Non-interactive mode, Up: Running the program
3.3.2 Interactive mode
----------------------
To enter the MIX virtual machine interactive mode, simply type
mixvm <RET>
at your shell command prompt. This command enters the 'mixvm' command
shell. You will be presented the following command prompt:
MIX >
The virtual machine is initialised and ready to accept your commands.
The 'mixvm' command shell uses GNU's readline, so that you have at your
disposal command completion (using <TAB>) and history functionality, as
well as other line editing shortcuts common to all utilities using this
library (for a complete description of readline's line editing usage,
see *note (Readline)Command Line Editing::.)
Usually, the first thing you will want to do is loading a compiled
MIX program into memory. This is accomplished by the 'load' command,
which takes as an argument the name of the '.mix' file to be loaded.
Thus, typing
MIX > load hello <RET>
Program loaded. Start address: 3000
MIX >
will load 'hello.mix' into the virtual machine's memory and set the
program counter to the address of the first instruction. You can obtain
the contents of the program counter using the command 'pc':
MIX > pc
Current address: 3000
MIX >
After loading it, you are ready to run the program, using, as you
surely have guessed, the 'run' command:
MIX > run
Running ...
MIXAL HELLO WORLD
... done
Elapsed time: 11 /Total program time: 11 (Total uptime: 11)
MIX >
Note that now the timing statistics are richer. You obtain the elapsed
execution time (i.e., the time spent executing instructions since the
last breakpoint), the total execution time for the program up to now
(which in our case coincides with the elapsed time, since there were no
breakpoints), and the total uptime for the virtual machine (you can load
and run more than one program in the same session)(1) (*note Interactive
mode-Footnote-1::). After running the program, the program counter will
point to the address after the one containing the 'HLT' instruction. In
our case, asking the value of the program counter after executing the
program will give us
MIX > pc
Current address: 3002
MIX >
You can check the contents of a memory cell giving its address as an
argument of the command 'pmem', like this
MIX > pmem 3001
3001: + 00 00 00 02 05 (0000000133)
MIX >
and convince yourself that address 3001 contains the binary
representation of the instruction 'HLT'. An address range of the form
FROM-TO can also be used as the argument of 'pmem':
MIX > pmem 3000-3006
3000: + 46 58 00 19 37 (0786957541)
3001: + 00 00 00 02 05 (0000000133)
3002: + 14 09 27 01 13 (0237350989)
3003: + 00 08 05 13 13 (0002118477)
3004: + 16 00 26 16 19 (0268542995)
3005: + 13 04 00 00 00 (0219152384)
3006: + 00 00 00 00 00 (0000000000)
MIX >
In a similar manner, you can look at the contents of the MIX registers
and flags. For instance, to ask for the contents of the A register you
can type
MIX > preg A
rA: + 00 00 00 00 00 (0000000000)
MIX >
Use the command 'help' to obtain a list of all available commands, and
'help COMMAND' for help on a specific command, e.g.
MIX > help run
run Run loaded or given MIX code file. Usage: run [FILENAME]
MIX >
For a complete list of commands available at the MIX propmt, *Note
mixvm::. In the following subsection, you will find a quick tour over
commands useful for debugging your programs.
File: mdk.info, Node: Interactive mode-Footnotes, Up: Interactive mode
(1) Printing of timing statistics can be disabled using the command
'timing' (*note Configuration commands::).
File: mdk.info, Node: Debugging, Prev: Interactive mode, Up: Running the program
3.3.3 Debugging commands
------------------------
The interactive mode of 'mixvm' lets you step by step execution of
programs as well as breakpoint setting. Use 'next' to step through the
program, running its instructions one by one. To run our
two-instruction 'hello.mix' sample you can do the following:
MIX > load hello
Program loaded. Start address: 3000
MIX > pc
Current address: 3000
MIX > next
MIXAL HELLO WORLD
Elapsed time: 1 /Total program time: 1 (Total uptime: 1)
MIX > pc
Current address: 3001
MIX > next
End of program reached at address 3002
Elapsed time: 10 /Total program time: 11 (Total uptime: 11)
MIX > pc
Current address: 3002
MIX > next
MIXAL HELLO WORLD
Elapsed time: 1 /Total program time: 1 (Total uptime: 12)
MIX >
MIX > run
Running ...
... done
Elapsed time: 10 /Total program time: 11 (Total uptime: 22)
MIX >
(As an aside, the above sample also shows how the virtual machine
handles cumulative time statistics and automatic program restart).
You can set a breakpoint at a given address using the command 'sbpa'
(set breakpoint at address). When a breakpoint is set, 'run' will stop
before executing the instruction at the given address. Typing 'run'
again will resume program execution. Coming back to our hello world
example, we would have:
MIX > sbpa 3001
Breakpoint set at address 3001
MIX > run
Running ...
MIXAL HELLO WORLD
... stopped: breakpoint at line 8 (address 3001)
Elapsed time: 1 /Total program time: 1 (Total uptime: 23)
MIX > run
Running ...
... done
Elapsed time: 10 /Total program time: 11 (Total uptime: 33)
MIX >
Note that, since we compiled 'hello.mixal' with debug info enabled, the
virtual machine is able to tell us the line in the source file
corresponding to the breakpoint we are setting. As a matter of fact,
you can directly set breakpoints at source code lines using the command
'sbp LINE_NO', e.g.
MIX > sbp 4
Breakpoint set at line 7
MIX >
'sbp' sets the breakpoint at the first meaningful source code line;
thus, in the above example we have requested a breakpoint at a line
which does not correspond to a MIX instruction and the breakpoint is set
at the first line containing a real instruction after the given one. To
unset breakpoints, use 'cbpa ADDRESS' and 'cbp LINE_NO', or 'cabp' to
remove all currently set breakpoints. You can also set conditional
breakpoints, i.e., tell 'mixvm' to interrupt program execution whenever
a register, a memory cell, the comparison flag or the overflow toggle
change using the commands 'sbp[rmco]' (*note Debug commands::).
MIXAL lets you define symbolic constants, either using the 'EQU'
pseudoinstruction or starting an instruction line with a label (which
assigns to the label the value of the current memory address). Each
MIXAL program has, therefore, an associated symbol table which you can
inspect using the 'psym' command. For our hello world sample, you will
obtain the following output:
MIX > psym
START: 3000
TERM: 19
MSG: 3002
MIX >
Other useful commands for debugging are 'strace' (which turns on
tracing of executed instructions), 'pbt' (which prints a backtrace of
executed instructions) and 'weval' (which evaluates w-expressions on the
fly). For a complete description of all available MIX commands, *Note
mixvm::.
File: mdk.info, Node: Using mixguile, Next: Using Scheme in mixvm and gmixvm, Prev: Running the program, Up: Getting started
3.4 Using 'mixguile'
====================
With 'mixguile' you can run a MIX simulator embedded in a Guile shell,
that is, using Scheme functions and programs. As with 'mixvm',
'mixguile' can be run both in interactive and non-interactive modes.
The following subsections provide a quick tour on using this MIX
emulator.
* Menu:
* The mixguile shell:: Using the Scheme MIX virtual machine.
* Additional functions:: Scheme functions accessing the VM.
* Defining new functions:: Defining your own Scheme functions.
* Hook functions:: Using command and break hook functions.
* Scheme scripts::
File: mdk.info, Node: The mixguile shell, Next: Additional functions, Prev: Using mixguile, Up: Using mixguile
3.4.1 The 'mixguile' shell
--------------------------
If you simply type
mixguile <RET>
at the command prompt, you'll be presented a Guile shell prompt like
this
guile>
At this point, you have entered a Scheme read-eval-print loop (REPL)
which offers you all the Guile functionality plus a new set of built-in
procedures to execute and debug MIX programs. Each of the 'mixvm'
commands described in the previous sections (and in *note mixvm::) have
a Scheme function counterpart named after it by prepending the prefix
'mix-' to its name. Thus, to load our hello world program, you can
simply enter
guile> (mix-load "hello")
Program loaded. Start address: 3000
guile>
and run it using 'mix-run':
guile> (mix-run)
Running ...
MIXAL HELLO WORLD
... done
Elapsed time: 11 /Total program time: 11 (Total uptime: 11)
guile>
In the same way, you can execute it step by step using the Scheme
function 'mix-next' or set a breakpoint:
guile> (mix-sbp 4)
Breakpoint set at line 5
guile>
or, if you one to peek at a register contents:
guile> (mix-preg 'A)
rA: + 00 00 00 00 00 (0000000000)
guile>
You get the idea: you have at your disposal all the 'mixvm' and
'gmixvm' commands by means of 'mix-' functions. But, in case you are
wondering, this is only the beginning. You also have at your disposal a
whole Scheme interpreter, and you can, for instance, define new
functions combining the 'mix-' and all other Scheme primitives. In the
next sections, you'll find examples of how to take advantage of the
Guile interpreter.
File: mdk.info, Node: Additional functions, Next: Defining new functions, Prev: The mixguile shell, Up: Using mixguile
3.4.2 Additional MIX Scheme functions
-------------------------------------
The 'mix-' function counterparts of the 'mixvm' commands don't return
any value, and are evaluated only for their side-effects (possibly
including informational messages to the standard output and/or error
stream). When writing your own Scheme functions to manipulate the MIX
virtual machine within 'mixguile' (*note Defining new functions::),
you'll probably need Scheme functions returning the value of the
registers, memory cells and so on. Don't worry: 'mixguile' also offers
you such functions. For instance, to access the (numerical) value of a
register you can use 'mix-reg':
guile> (mix-reg 'I2)
0
guile>
Note that, unlike '(mix-preg 'I2)', the expression '(mix-reg 'I2)' in
the above example evaluates to a Scheme number and does not produce any
side-effect:
guile> (number? (mix-reg 'I2))
#t
guile> (number? (mix-preg 'I2))
rI2: + 00 00 (0000)
#f
guile>
In a similar fashion, you can access the memory contents using
'(mix-cell)', or the program counter using '(mix-loc)':
guile> (mix-cell 3000)
786957541
guile> (mix-loc)
3002
guile>
Other functions returning the contents of the virtual machine
components are 'mix-cmp' and 'mix-over', which eval to the value of the
comparison flag and the overflow toggle respectively. For a complete
list of these additional functions, *Note mixguile::.
In the next section, we'll see a sample of using these functions to
extend 'mixguile''s functionality.
File: mdk.info, Node: Defining new functions, Next: Hook functions, Prev: Additional functions, Up: Using mixguile
3.4.3 Defining new functions
----------------------------
Scheme is a powerful language, and you can use it inside 'mixguile' to
easily extend the MIX interpreter's capabilities. For example, you can
easily define a function that loads a file, prints its name, executes it
and, finally, shows the registers contents, all in one shot:
guile> (define my-load-and-run <RET>
(lambda (file) <RET>
(mix-load file) <RET>
(display "File loaded: ") <RET>
(mix-pprog) <RET>
(mix-run) <RET>
(mix-preg))) <RET>
guile>
and use it to run your programs:
guile> (my-load-and-run "hello")
Program loaded. Start address: 3000
File loaded: hello.mix
Running ...
MIXAL HELLO WORLD
... done
Elapsed time: 11 /Total program time: 11 (Total uptime: 33)
rA: + 00 00 00 00 00 (0000000000)
rX: + 00 00 00 00 00 (0000000000)
rJ: + 00 00 (0000)
rI1: + 00 00 (0000) rI2: + 00 00 (0000)
rI3: + 00 00 (0000) rI4: + 00 00 (0000)
rI5: + 00 00 (0000) rI6: + 00 00 (0000)
guile>
Or, maybe, you want a function which sets a breakpoint at a specified
line number before executing it:
guile> (define my-load-and-run-with-bp
(lambda (file line)
(mix-load file)
(mix-sbp line)
(mix-run)))
guile> (my-load-and-run-with-bp "samples/primes" 10)
Program loaded. Start address: 3000
Breakpoint set at line 10
Running ...
... stopped: breakpoint at line 10 (address 3001)
Elapsed time: 1 /Total program time: 1 (Total uptime: 45)
guile>
As a third example, the following function loads a program, runs it
and prints the contents of the memory between the program's start and
end addresses:
guile> (define my-run
(lambda (file)
(mix-load file)
(let ((start (mix-loc)))
(mix-run)
(mix-pmem start (mix-loc)))))
guile> (my-run "hello")
Program loaded. Start address: 3000
Running ...
MIXAL HELLO WORLD
... done
Elapsed time: 11 /Total program time: 11 (Total uptime: 11)
3000: + 46 58 00 19 37 (0786957541)
3001: + 00 00 00 02 05 (0000000133)
3002: + 14 09 27 01 13 (0237350989)
guile>
As you can see, the possibilities are virtually unlimited. Of
course, you don't need to type a function definition each time you start
'mixguile'. You can write it in a file, and load it using Scheme's
'load' function. For instance, you can create a file named, say,
'functions.scm' with your definitions (or any Scheme expression) and
load it at the 'mixguile' prompt:
guile> (load "functions.scm")
Alternatively, you can make 'mixguile' to load it for you. When
'mixguile' starts, it looks for a file named 'mixguile.scm' in your MDK
configuration directory ('~/.mdk') and, if it exists, loads it before
entering the REPL. Therefore, you can copy your definitions in that
file, or load the 'functions.scm' file in 'mixguile.scm'.
File: mdk.info, Node: Hook functions, Next: Scheme scripts, Prev: Defining new functions, Up: Using mixguile
3.4.4 Hook functions
--------------------
Hooks are functions called before or after a given event occurs. In
'mixguile', you can define command and break hooks, which are
associated, respectively, with command execution and program
interruption events. The following sections give you a tutorial on
using hook functions within 'mixguile'.
* Menu:
* Command hooks::
* Break hooks::
File: mdk.info, Node: Command hooks, Next: Break hooks, Prev: Hook functions, Up: Hook functions
3.4.4.1 Command hooks
.....................
In the previous section, we have seen how to extend 'mixguile''s
functionality through the use of user defined functions. Frequently,
you'll write new functions that improve in some way the workings of a
built-in 'mixvm' command, following this pattern:
a. Prepare the command execution
b. Execute the desired command
c. Perform post execution operations
We call the functions executed in step (a) "pre-hook"s, and those of
step "post-hook"s of the given command. 'mixguile' lets you specify
pre- and post-hooks for any 'mixvm' command using the 'mix-add-pre-hook'
and 'mix-add-post-hook' functions, which take as arguments a symbol
naming the command and a function to be executed before (resp. after)
the command. In other words, 'mixguile' will execute for you steps (a)
and (c) above whenever you eval (b). The hook functions must take a
single argument, which is a string list of the command's arguments. As
an example, let us define the following hooks for the 'next' command:
(define next-pre-hook
(lambda (arglist)
(mix-slog #f)))
(define next-post-hook
(lambda (arglist)
(display "Stopped at line ")
(display (mix-src-line-no))
(display ": ")
(display (mix-src-line))
(newline)
(mix-slog #t)))
In these functions, we are using the function 'mix-slog' to turn off the
informational messages produced by the virtual machine, since we are
providing our own ones in the post hook function. To install these
hooks, we would write:
(mix-add-pre-hook 'next next-pre-hook)
(mix-add-post-hook 'next next-post-hook)
Assuming we have put the above expressions in 'mixguile''s
initialisation file, we would obtain the following results when
evaluating 'mix-next':
guile> (mix-next)
MIXAL HELLO WORLD
Stopped at line 6: HLT
guile>
As a second, more elaborate, example, let's define hooks which print
the address and contents of a cell being modified using 'smem'. The
hook functions could be something like this:
(define smem-pre-hook
(lambda (arglist)
(if (eq? (length arglist) 2)
(begin
(display "Changing address ")
(display (car arglist))
(newline)
(display "Old contents: ")
(display (mix-cell (string->number (car arglist))))
(newline))
(error "Wrong arguments" arglist))))
(define smem-post-hook
(lambda (arglist)
(if (eq? (length arglist) 2)
(begin
(display "New contents: ")
(display (mix-cell (string->number (car arglist))))
(newline)))))
and we can install them using
(mix-add-pre-hook 'smem smem-pre-hook)
(mix-add-post-hook 'smem smem-post-hook)
Afterwards, a sample execution of 'mix-smem' would look like this:
guile> (mix-smem 2000 100)
Changing address 2000
Old contents: 0
New contents: 100
guile>
You can add any number of hooks to a given command. They will be
executed in the same order as they are registered. You can also define
global post (pre) hooks, which will be called before (after) any 'mixvm'
command is executed. Global hook functions must admit two arguments,
namely, a string naming the invoked command and a string list of its
arguments, and they are installed using the Scheme functions
'mix-add-global-pre-hook' and 'mix-add-global-post-hook'. A simple
example of global hook would be:
guile> (define pre-hook
(lambda (cmd args)
(display cmd)
(display " invoked with arguments ")
(display args)
(newline)))
guile> (mix-add-global-pre-hook pre-hook)
ok
guile> (mix-pmem 120 125)
pmem invoked with arguments (120-125)
0120: + 00 00 00 00 00 (0000000000)
0121: + 00 00 00 00 00 (0000000000)
0122: + 00 00 00 00 00 (0000000000)
0123: + 00 00 00 00 00 (0000000000)
0124: + 00 00 00 00 00 (0000000000)
0125: + 00 00 00 00 00 (0000000000)
guile>
Note that if you invoke 'mixvm' commands within a global hook, its
associated command hooks will be run. Thus, if you have installed both
the 'next' hooks described earlier and the global hook above, executing
'mix-next' will yield the following result:
guile> (mix-next 5)
next invoked with arguments (5)
slog invoked with arguments (off)
MIXAL HELLO WORLD
Stopped at line 7: MSG ALF "MIXAL"
slog invoked with arguments (on)
guile>
Adventurous readers may see the above global hook as the beginning of
a command log utility or a macro recorder that saves your commands for
replay.
File: mdk.info, Node: Break hooks, Prev: Command hooks, Up: Hook functions
3.4.4.2 Break hooks
...................
We have seen in the previous section how to associate hooks to command
execution, but they are not the whole story. You can also associate
hook functions to program interruption, that is, specify functions that
should be called every time the execution of a MIX program is stopped
due to the presence of a breakpoint, either explicit or conditional.
Break hooks take as arguments the line number and memory address at
which the break occurred. A simple hook that logs the line and address
of the breakpoint could be defined as:
(define break-hook
(lambda (line address)
(display "Breakpoint encountered at line ")
(display line)
(display " and address ")
(display address)
(newline)))
and installed for explicit and conditional breakpoints using
(mix-add-break-hook break-hook)
(mix-add-cond-break-hook break-hook)
after that, every time the virtual machine encounters a breakpoint,
'break-code' shall be evaluated for you(1) (*note Break
hooks-Footnote-1::).
File: mdk.info, Node: Break hooks-Footnotes, Up: Break hooks
(1) You may have noticed that break hooks can be implemented in terms
of command hooks associated to 'mix-run' and 'mix-next'. As a matter of
fact, they _are_ implemented this way: take a look at the file
'_install_dir_/share/mdk/mix-vm-stat.scm' if you are curious.
File: mdk.info, Node: Scheme scripts, Prev: Hook functions, Up: Using mixguile
3.4.5 Scheme scripts
--------------------
Another useful way of using 'mixguile' is writing executable scripts
that perform a set of commands for you. This is done using the
'mixguile' switch '-s' (being a Guile shell, 'mixguile' accepts all the
command options of 'guile'; type 'mixguile -h' for a list of all
available command options). For instance, if you have a very useful MIX
program 'foo.mix' which you want to run often, you don't have to fire up
a MIX virtual machine, load and run it every time; you can write a
Scheme script instead:
#! /usr/bin/mixguile -s
!#
;;; runprimes: execute the primes.mix program
;; load the file you want to run
(mix-load "../samples/primes")
;; execute it
(mix-run)
;; print the contents of registers
(mix-pall)
;; ...
Just save the above script to a file named, say, 'runtest', make it
executable ('chmod +x runtest'), and, well, execute it from the Unix
shell:
$ ./runtest
Program loaded. Start address: 3000
Running ...
... done
Elapsed time: 190908 /Total program time: 190908 (Total uptime: 190908)
rA: + 30 30 30 30 30 (0511305630)
rX: + 30 30 32 32 39 (0511313959)
rJ: + 47 18 (3026)
rI1: + 00 00 (0000) rI2: + 55 51 (3571)
rI3: + 00 19 (0019) rI4: + 31 51 (2035)
rI5: + 00 00 (0000) rI6: + 00 00 (0000)
Overflow: F
Cmp: L
$
Note that this is far more flexible that running programs
non-interactively using 'mixvm' (*note Non-interactive mode::), for you
can execute any combination of commands you want from a Scheme script
(not just running and dumping the registers). For additional 'mixguile'
command line options, see *note Invoking mixguile::.
File: mdk.info, Node: Using Scheme in mixvm and gmixvm, Prev: Using mixguile, Up: Getting started
3.5 Using Scheme in 'mixvm' and 'gmixvm'
========================================
In the previous section (*note Using mixguile::) we have seen how the
Guile shell 'mixguile' offers you the possibility of using Scheme to
manipulate a MIX virtual machine and extend the set of commands offered
by 'mixvm' and 'gmixvm'. This possibility is not limited to the
'mixguile' shell. Actually, both 'mixvm' and 'gmixvm' incorporate an
embedded Guile interpreter, and can evaluate Scheme expressions. To
evaluate a single-line expression at the 'mixvm' or 'gmixvm' command
prompt, simply write it and press return (the command parser will
recognise it as a Scheme expression because it is parenthesized, and
will pass it to the Guile interpreter). A sample 'mixvm' session using
Scheme expressions could be:
MIX > load hello
Program loaded. Start address: 3000
MIX > (define a (mix-loc))
MIX > run
Running ...
MIXAL HELLO WORLD
... done
Elapsed time: 11 /Total program time: 11 (Total uptime: 11)
MIX > (mix-pmem a)
3000: + 46 58 00 19 37 (0786957541)
MIX > (mix-pmem (mix-loc))
3002: + 14 09 27 01 13 (0237350989)
MIX >
You can also load and evaluate a file, using the 'scmf' command like
this:
MIX> scmf /path/to/file/file.scm
Therefore, you have at your disposal all the 'mixguile' goodies
described above (new functions, new command definitions, hooks...)
inside 'mixvm' and 'gmixvm'. In other words, these programs are
extensible using Scheme. See *note Using mixguile:: for examples of how
to do it.
File: mdk.info, Node: Emacs tools, Next: mixasm, Prev: Getting started, Up: Top
4 Emacs tools
*************
Everyone writing code knows how important a good editor is. Most
systems already come with Emacs, and excellent programmer's editor. MDK
adds support to Emacs for both writing and debugging MIX programs. A
major mode for MIXAL source files eases edition of your code, while
integration with Emacs' debugging interface (GUD) lets you use 'mixvm'
without leaving your favourite text editor.
This chapter shows how to use the Elisp modules included in MDK,
assuming that you have followed the installation instructions in *Note
Emacs support::.
* Menu:
* MIXAL mode:: Editing MIXAL files.
* GUD integration:: Invoking 'mixvm' within Emacs.
File: mdk.info, Node: MIXAL mode, Next: GUD integration, Prev: Emacs tools, Up: Emacs tools
4.1 MIXAL mode
==============
The module 'mixal-mode.el' provides a new mode, mixal-mode, for editing
MIXAL source files(1) (*note MIXAL mode-Footnote-1::). When everything
is installed correctly, Emacs will select it as the major mode for
editing files with extension '.mixal'. You can also activate mixal-mode
in any buffer issuing the Emacs command 'M-x mixal-mode'.
* Menu:
* Basics:: Editing code, font locking and indentation.
* Help system:: Using the interactive help system.
* Compiling and running:: Invoking compiler and/or virtual machine.
File: mdk.info, Node: MIXAL mode-Footnotes, Up: MIXAL mode
(1) mixal-mode has been developed and documented by Pieter E. J.
Pareit
File: mdk.info, Node: Basics, Next: Help system, Prev: MIXAL mode, Up: MIXAL mode
4.1.1 Basics
------------
The mode for editing mixal source files is inherited from
fundamental-mode, meaning that all your favorite editing operations will
still work. If you want a short introduction to Emacs, type 'C-h t'
inside Emacs to start the tutorial.
Mixal mode adds font locking. If you do not have font locking
globally enabled, you can turn it on for mixal-mode by placing the
following line in your '.emacs' file:
(add-hook 'mixal-mode-hook 'turn-on-font-lock)
You can also customize the colors used to colour your mixal code by
changing the requisite faces. This is the list of faces used by
mixal-mode:
* FONT-LOCK-COMMENT-FACE Face to use for comments.
* MIXAL-FONT-LOCK-LABEL-FACE Face to use for label names.
* MIXAL-FONT-LOCK-OPERATION-CODE-FACE Face to use for operation code
names.
* MIXAL-FONT-LOCK-ASSEMBLY-PSEUDOINSTRUCTION-FACE Face to use for
assembly pseudo-instruction names.
File: mdk.info, Node: Help system, Next: Compiling and running, Prev: Basics, Up: MIXAL mode
4.1.2 Help system
-----------------
When coding your program, you will be thinking, looking up documentation
and editing files. Emacs already helps you with editing files, but
Emacs can do much more. In particular, looking up documentation is one
of its strong points. Besides the info system (which you are probably
already using), mixal-mode defines commands for getting particular
information about a MIX operation code.
With 'M-x mixal-describe-operation-code' (or its keyboard shortcut
'C-h o') you will get the documentation about a particular MIX operation
code. Keep in mind that these are not assembly (MIXAL)
pseudoinstructions. When the 'point' is around a MIXAL
pseudoinstruction in your source file, Emacs will recognize it and will
suggest the right MIX operation code.
File: mdk.info, Node: Compiling and running, Prev: Help system, Up: MIXAL mode
4.1.3 Compiling and running
---------------------------
After you have written your MIXAL program, you'll probably want to test
it. This can be done with the MIX virtual machine. First you will need
to compile your code into MIX byte code. This can be done within Emacs
with the command 'M-x compile' ('C-c c'). In case of compilation
errors, you can jump to the offending source code line with 'M-x
next-error'.
Once the program compiles without errors, you can debug or run it.
To invoke the debugger, use 'M-x mixal-debug' ('C-c d'). Emacs will
open a 'GUD' buffer where you can use the debugging commands described
in *Note mixvm::.
If you just want to execute the program, you can do so with 'M-x
mixal-run' ('C-c r'). This will invoke mixvm, execute the program and
show its output in a separate buffer.
File: mdk.info, Node: GUD integration, Prev: MIXAL mode, Up: Emacs tools
4.2 GUD integration
===================
If you are an Emacs user and write your MIXAL programs using this
editor, you will find the elisp program 'mixvm.el' quite useful(1)
(*note GUD integration-Footnote-1::). 'mixvm.el' allows running the MIX
virtual machine 'mixvm' (*note mixvm::) inside an Emacs GUD buffer,
while visiting the MIXAL source file in another buffer.
After installing 'mixvm.el' (*note Emacs support::), you can initiate
an MDK/GUD session inside Emacs with the command
M-x mixvm
and you will have a 'mixvm' prompt inside a newly created GUD buffer.
GUD will reflect the current line in the corresponding source file
buffer.
File: mdk.info, Node: GUD integration-Footnotes, Up: GUD integration
(1) 'mixvm.el' has been kindly contributed by Philip E. King.
'mixvm.el' is based on a study of gdb, perldb, and pdb as found in
'gud.el', and 'rubydb3x.el' distributed with the source code to the Ruby
language.
File: mdk.info, Node: mixasm, Next: mixvm, Prev: Emacs tools, Up: Top
5 'mixasm', the MIXAL assembler
*******************************
MIX programs, as executed by 'mixvm', are composed of binary
instructions loaded into the virtual machine memory as MIX words.
Although you could write your MIX programs directly as a series of words
in binary format, you have at your disposal a more friendly assembly
language, MIXAL (*note MIXAL::) which is compiled into binary form by
'mixasm', the MIXAL assembler included in MDK. In this chapter, you
will find a complete description of 'mixasm' options.
* Menu:
* Invoking mixasm::
File: mdk.info, Node: Invoking mixasm, Prev: mixasm, Up: mixasm
5.1 Invoking 'mixasm'
=====================
In its simplest form, 'mixasm' is invoked with a single argument, which
is the name of the MIXAL file to be compiled, e.g.
mixasm hello
will compile either 'hello' or 'hello.mixal', producing a binary file
named 'hello.mix' if no errors are found.
In addition, 'mixasm' can be invoked with the following command line
options (note, that, following GNU's conventions, we provide a long
option name for each available single letter switch):
mixasm [-vhulO] [-o OUTPUT_FILE] [--version] [--help] [--usage]
[--ndebug] [--output=OUTPUT_FILE] [--list[=LIST_FILE]] file
The meaning of these options is as follows:
-- User Option: -v
-- User Option: --version
Prints version and copyleft information and exits.
-- User Option: -h
-- User Option: --help
-- User Option: -u
-- User Option: --usage
Prints a summary of available options and exits.
-- User Option: -O
-- User Option: --ndebug
Do not include debugging information in the compiled file, saving
space but disallowing breakpoint setting at source level and symbol
table inspection under 'mixvm'.
-- User Option: -o output_file
-- User Option: --output=output_file
By default, the given source file FILE.MIXAL is compiled into
FILE.MIX. You can provide a different name for the output file
using this option.
-- User Option: -l
-- User Option: --list[=list_file]
This option causes 'mixasm' to produce, in addition to the '.mix'
file, an ASCII file containing a summary of the compilation
results. The file is named after the MIXAL source file, changing
its extension to '.mls' if no argument is provided; otherwise, the
listing file is named according to the argument.
File: mdk.info, Node: mixvm, Next: gmixvm, Prev: mixasm, Up: Top
6 'mixvm', the MIX computer simulator
*************************************
This chapter describes 'mixvm', the MIX computer simulator. 'mixvm' is
a command line interface programme which simulates the MIX computer
(*note The MIX computer::). It is able to run MIXAL programs (*note
MIXAL::) previously compiled with the MIX assembler (*note mixasm::).
The simulator allows inspection of the MIX computer components
(registers, memory cells, comparison flag and overflow toggle), step by
step execution of MIX programmes, and breakpoint setting to aid you in
debugging your code. For a tutorial description of 'mixvm' usage, *Note
Running the program::.
* Menu:
* Invocation::
* Commands:: Commands available in interactive mode.
* Devices:: MIX block devices implementation.
File: mdk.info, Node: Invocation, Next: Commands, Prev: mixvm, Up: mixvm
6.1 Invoking 'mixvm'
====================
'mixvm' can be invoked with the following command line options (note
that, following GNU's conventions, we provide a long option name for
each available single letter switch):
mixvm [-vhurdtq] [--version] [--help] [--usage] [--run] [--dump]
[--time] [--noinit] [FILE[.mix]]
The meaning of these options is as follows:
-- User Option: -v
-- User Option: --version
Prints version and copyleft information and exits.
-- User Option: -h
-- User Option: --help
-- User Option: -u
-- User Option: --usage
Prints a summary of available options and exits.
-- User Option: -r
-- User Option: --run
Loads the specified FILE and executes it. After the program
execution, 'mixvm' exits. FILE must be the name of a binary '.mix'
program compiled with 'mixasm'. If your program does not produce
any output, use the '-d' flag (see below) to peek at the virtual
machine's state after execution.
-- User Option: -d
-- User Option: --dump
This option must be used in conjunction with '-r', and tells
'mixvm' to print the value of the virtual machine's registers,
comparison flag and overflow toggle after executing the program
named FILE. See *Note Non-interactive mode::, for sample usage.
-- User Option: -t
-- User Option: --time
This option must be used in conjunction with '-r', and tells
'mixvm' to print virtual time statistics for the program's
execution.
When run without the '-r' flag, 'mixvm' enters its interactive mode,
showing you a prompt like this one:
MIX >
and waiting for your commands (*note Commands::). If the optional FILE
argument is given, the file 'FILE.mix' will be loaded into the virtual
machine memory before entering the interactive mode.
The first time 'mixvm' is invoked, a directory named '.mdk' is
created in your home directory. It contains the 'mixvm' configuration
file, the command history file and (by default) the block devices files
(*note Devices::). Before showing you the command prompt, 'mixvm' looks
in the '~/.mdk' directory for a file named 'mixguile.scm'; if it exists,
it is read and evaluated by the embedded Guile interpreter (*note
Defining new functions::). You can use the '-q' command line option to
skip this file loading:
-- User Option: -q
-- User Option: --noinit
Do not load the Guile initialisation file '~/.mdk/mixguile.scm' at
startup.
File: mdk.info, Node: Commands, Next: Devices, Prev: Invocation, Up: mixvm
6.2 Interactive commands
========================
You can enter the interactive mode of the MIX virtual machine by simply
invoking 'mixvm' without arguments. You will then be greeted by a shell
prompt(1) (*note Commands-Footnote-1::)
MIX >
which indicates that a new virtual machine has been initialised and is
ready to execute your commands. As we have already mentioned, this
command prompt offers you command line editing facilities which are
described in the Readline user's manual (chances are that you are
already familiar with these command line editing capabilities, as they
are present in many GNU utilities, e.g. the 'bash' shell)(2) (*note
Commands-Footnote-2::). In a nutshell, readline provides command
completion using the 'TAB' key and command history using the cursor
keys. A history file containing the last commands typed in previous
sessions is stored in the MDK configuration directory ('~/.mdk').
As a beginner, your best friend will be the 'help' command, which
shows you a summary of all available MIX commands and their usage; its
syntax is as follows:
-- 'mixvm' command: help [command]
Prints a short description of the given COMMAND and its usage. If
COMMAND is omitted, 'help' prints the short description for all
available commands.
* Menu:
* File commands:: Loading and executing programs.
* Debug commands:: Debugging programs.
* State commands:: Inspecting the virtual machine state.
* Configuration commands:: Changing and storing mixvm settings.
* Scheme commands::
File: mdk.info, Node: Commands-Footnotes, Up: Commands
(1) The default command prompt, 'MIX > ', can be changed using the
'prompt' command (*note Configuration commands::)
(2) The readline functionality will be available if you have compiled
MDK with readline support, i.e., if GNU readline is installed in your
system. This is often the case in GNU/Linux and BSD systems
File: mdk.info, Node: File commands, Next: Debug commands, Prev: Commands, Up: Commands
6.2.1 File commands
-------------------
You have at your disposal a series of commands that let you load and
execute MIX executable files, as well as manipulate MIXAL source files:
-- file command: load file[.mix]
This command loads a binary file, FILE.MIX into the virtual machine
memory, and positions the program counter at the beginning of the
loaded program. This address is indicated in the MIXAL source file
as the operand of the 'END' pseudoinstruction. Thus, if your
'sample.mixal' source file contains the line:
END 3000
and you compile it with 'mixasm' to produce the binary file
'sample.mix', you will load it into the virtual machine as follows:
MIX > load sample
Program loaded. Start address: 3000
MIX >
-- file command: run [file[.mix]]
When executed without argument, this command initiates or resumes
execution of instructions from the current program counter address.
Therefore, issuing this command after a successful 'load', will run
the loaded program until either a 'HLT' instruction or a breakpoint
is found. If you provide a MIX filename as argument, the given
file will be loaded (as with 'load' FILE) and executed. If 'run'
is invoked again after program execution completion (i.e., after
the 'HLT' instruction has been found in a previous run), the
program counter is repositioned and execution starts again from the
beginning (as a matter of fact, a 'load' command preserving the
currently set breakpoints is issued before resuming execution).
-- file command: edit [file[.mixal]]
The source file FILE.MIXAL is edited using the editor defined in
the environment variable MDK_EDITOR. If this variable is not set,
the following ones are tried out in order: X_EDITOR, EDITOR and
VISUAL. If invoked without argument, the source file for the
currently loaded MIX file is edited. The command used to edit
source files can also be configured using the 'sedit' command
(*note Configuration commands::).
-- file command: compile file[.mixal]
The source file FILE.MIXAL is compiled (with debug information
enabled) using 'mixasm'. If invoked without argument, the source
file for the currently loaded MIX file is recompiled. The
compilation command can be set using the 'sasm' command (*note
Configuration commands::).
-- file command: pprog
-- file command: psrc
Print the path of the currently loaded MIX program and its source
file:
MIX > load ../samples/primes
Program loaded. Start address: 3000
MIX > pprog
../samples/primes.mix
MIX > psrc
/home/jao/projects/mdk/gnu/samples/primes.mixal
MIx>
Finally, you can use the 'quit' command to exit 'mixvm':
-- file command: quit
Exit 'mixvm', saving the current configuration parameters in
'~/.mdk/mixvm.config'.
File: mdk.info, Node: Debug commands, Next: State commands, Prev: File commands, Up: Commands
6.2.2 Debug commands
--------------------
Sequential execution of loaded programs can be interrupted using the
following debug commands:
-- debug command: next [ins_number]
This command causes the virtual machine to fetch and execute up to
INS_NUMBER instructions, beginning from the current program counter
position. Execution is interrupted either when the specified
number of instructions have been fetched or a breakpoint is found,
whatever happens first. If run without arguments, one instruction
is executed. If 'next' is invoked again after program execution
completion (i.e., after the 'HLT' instruction has been found in a
previous run), the program counter is repositioned and execution
starts again from the beginning (as a matter of fact, a 'load'
command preserving the currently set breakpoints is issued before
resuming execution).
-- debug command: sbp line_number
-- debug command: cbp line_no
Sets a breakpoint at the specified source file line number. If the
line specified corresponds to a command or to a MIXAL
pseudoinstruction which does not produce a MIX instruction in the
binary file (such as 'ORIG' or 'EQU') the breakpoint is set at the
first source code line giving rise to a MIX instruction after the
specified one. Thus, for our sample 'hello.mixal' file:
* (1)
* hello.mixal: say 'hello world' in MIXAL (2)
* (3)
* label ins operand comment (4)
TERM EQU 19 the MIX console device number (5)
ORIG 1000 start address (6)
START OUT MSG(TERM) output data at address MSG (7)
...
trying to set a breakpoint at line 5, will produce the following
result:
MIX > sbp 5
Breakpoint set at line 7
MIX >
since line 7 is the first one compiled into a MIX instruction (at
address 3000).
The command 'cbp' clears a (previously set) breakpoint at the given
source file line.
-- debug command: spba address
-- debug command: cbpa address
Sets a breakpoint at the given memory ADDRESS. The argument must
be a valid MIX memory address, i.e., it must belong into the range
[0-3999]. Note that no check is performed to verify that the
specified address is reachable during program execution. No debug
information is needed to set a breakpoint by address with 'sbpa'.
The command 'cbpa' clears a (previously set) breakpoint at the
given memory address.
-- debug command: sbpr A | X | J | Ii
-- debug command: cbpr A | X | J | Ii
Sets a conditional breakpoint on the specified register change.
For instance,
sbpr I1
will cause an interruption during program execution whenever the
contents of register 'I1' changes. A previously set breakpoint is
cleared using the 'cbpr' command.
-- debug command: sbpm address
-- debug command: cbpm address
Sets a conditional breakpoint on the specified memory cell change.
The argument must be a valid MIX memory address, i.e., it must
belong into the range [0-3999]. For instance,
sbpm 1000
will cause an interruption during program execution whenever the
contents of the memory cell number 1000 changes. A previously set
breakpoint is cleared using the 'cbpm' command.
-- debug command: sbpo
-- debug command: cbpo
Sets/clears a conditional breakpoint on overflow toggle change.
-- debug command: sbpc
-- debug command: cbpc
Sets/clears a conditional breakpoint on comparison flag change.
-- debug command: cabp
Clears all currently set breakpoints.
-- debug command: psym [symbol_name]
MIXAL programs can define symbolic constants, using either the
'EQU' pseudoinstruction or a label at the beginning of a line.
Thus, in the program fragment
VAR EQU 2168
ORIG 4000
START LDA VAR
the symbol 'VAR' stands for the value 2168, while 'START' is
assigned the value 4000. The symbol table can be consulted from
the 'mixvm' command line using 'psym' followed by the name of the
symbol whose contents you are interested in. When run without
arguments, 'psym' will print all defined symbols and their values.
The virtual machine can also show you the instructions it is
executing, using the following commands:
-- debug command: strace [on|off]
'strace on' enables instruction tracing. When tracing is enabled,
each time the virtual machine executes an instruction (due to your
issuing a 'run' or 'next' command), it is printed in its canonical
form (that is, with all expressions evaluated to their numerical
values) and, if the program was compiled with debug information, as
it was originally typed in the MIXAL source file. Instruction
tracing is disabled with 'strace off' command. A typical tracing
session could be like this:
MIX > strace on
MIX > next
3000: [OUT 3002,0(2:3)] START OUT MSG(TERM)
MIXAL HELLO WORLD
Elapsed time: 1 /Total program time: 1 (Total uptime: 1)
MIX > next
3001: [HLT 0,0] HLT
End of program reached at address 3002
Elapsed time: 10 /Total program time: 11 (Total uptime: 11)
MIX > strace off
MIX >
The executed instruction, as it was translated, is shown between
square brackets after the memory address, and, following it, you
can see the actual MIXAL code that was compiled into the executed
instruction. The tracing behaviour is stored as a configuration
parameter in '~/.mdk'.
-- debug command: pline [LINE_NUMBER]
Prints the requested source line (or the current one if LINE_NUMBER
is omitted:
MIX > load ../samples/hello
Program loaded. Start address: 3000
MIX > pline
Line 5: START OUT MSG(TERM)
MIX > pline 6
Line 6: HLT
MIX >
-- debug command: sbt [NUMBER]
This command changes the limit for the backtrace of executed
instructions. If the number is omitted, the command prints the
current limit. If you use a 0, backtraces are turned off. This
can improve performance. If you wish for all the instructions to
be logged, a -1 will enable that. The amount of memory required
for unlimited backtraces can be substantial for long-running
programs.
-- debug command: pbt [INS_NUMBER]
This command prints a backtrace of executed instructions. Its
optional argument INS_NUMBER is the number of instructions to
print. If it is omitted or equals zero, all executed instructions
are printed. For instance, if you compile and load the following
program ('bt.mixal'):
ORIG 0
BEG JMP *+1
JMP *+1
FOO JMP BAR
BAR HLT
END BEG
you could get the following traces:
MIX > load bt
Program loaded. Start address: 0
MIX > next
MIX > pbt
#0 BEG in bt.mixal:2
MIX > next
MIX > pbt
#0 1 in bt.mixal:3
#1 BEG in bt.mixal:2
MIX > run
Running ...
... done
MIX > pbt 3
#0 BAR in bt.mixal:5
#1 FOO in bt.mixal:4
#2 1 in bt.mixal:3
MIX > pbt
#0 BAR in bt.mixal:5
#1 FOO in bt.mixal:4
#2 1 in bt.mixal:3
#3 BEG in bt.mixal:2
MIX >
Note that the executed instruction trace gives you the label of the
executed line or, if it has no label, its address.
As you have probably observed, 'mixvm' prints timing statistics when
running programs. This behaviour can be controlled using the 'stime'
command (*note Configuration commands::).
'mixvm' is also able of evaluating w-expressions (*note
W-expressions::) using the following command:
-- debug command: weval WEXP
Evaluates the given w-expression, WEXP. The w-expression can
contain any currently defined symbol. For instance:
MIX > psym START
+ 00 00 00 46 56 (0000003000)
MIX > weval START(0:1),START(3:4)
+ 56 00 46 56 00 (0939716096)
MIX >
New symbols can be defined using the 'ssym' command:
-- debug command: ssym SYM WEXP
Defines the symbol named SYM with the value resulting from
evaluating WEXP, a w-expression. The newly defined symbol can be
used in subsequent 'weval' commands, as part of the expression to
be evaluated. E.g.,
MIX > ssym S 2+23*START
+ 00 00 18 19 56 (0000075000)
MIX > psym S
+ 00 00 18 19 56 (0000075000)
MIX > weval S(3:4)
+ 00 00 19 56 00 (0000081408)
MIX >
Finally, if you want to discover which is the decimal value of a MIX
word expressed as five bytes plus sign, you can use
-- debug command: w2d WORD
Computes the decimal value of the given word. WORD must be
expressed as a sign (+/-) followed by five space-delimited,
two-digit decimal values representing the five bytes composing the
word. The reverse operation (showing the word representation of a
decimal value) can be accomplished with 'weval'. For instance:
MIX > w2d - 01 00 00 02 02
-16777346
MIX > weval -16777346
- 01 00 00 02 02 (0016777346)
MIX >
File: mdk.info, Node: State commands, Next: Configuration commands, Prev: Debug commands, Up: Commands
6.2.3 State commands
--------------------
Inspection and modification of the virtual machine state (memory,
registers, overflow toggle and comparison flag contents) is accomplished
using the following commands:
-- state command: pstat
This commands prints the current virtual machine state, which can
be one of the following:
- No program loaded
- Program successfully loaded
- Execution stopped ('next' executed)
- Execution stopped: breakpoint encountered
- Execution stopped: conditional breakpoint encountered
- Program successfully terminated
-- state command: pc
Prints the current value of the program counter, which stores the
address of the next instruction to be executed in a non-halted
program.
-- state command: sreg A | X | J | I[1-6] value
-- state command: preg [A | X | J | I[1-6]]
-- state command: pall
'preg' prints the contents of a given MIX register. For instance,
'preg' A will print the contents of the A-register. When invoked
without arguments, all registers shall be printed:
MIX > preg
rA: - 00 00 00 00 35 (0000000035)
rX: + 00 00 00 15 40 (0000001000)
rJ: + 00 00 (0000)
rI1: + 00 00 (0000) rI2: + 00 00 (0000)
rI3: + 00 00 (0000) rI4: + 00 00 (0000)
rI5: + 00 00 (0000) rI6: + 00 00 (0000)
MIX >
As you can see in the above sample, the contents are printed as the
sign plus the values of the MIX bytes stored in the register and,
between parenthesis, the decimal representation of its module.
'pall' prints the contents of all registers plus the comparison
flag and overflow toggle.
Finally, 'sreg' Sets the contents of the given register to VALUE,
expressed as a decimal constant. If VALUE exceeds the maximum
value storable in the given register, 'VALUE mod MAXIMUM_VALUE' is
stored, e.g.
MIX > sreg I1 1000
MIX > preg I1
rI1: + 15 40 (1000)
MIX > sreg I1 1000000
MIX > preg I1
rI1: + 09 00 (0576)
MIX >
-- state command: pflags
-- state command: scmp E | G | L
-- state command: sover F | T
'pflags' prints the value of the comparison flag and overflow
toggle of the virtual machine, e.g.
MIX > pflags
Overflow: F
Cmp: E
MIX >
The values of the overflow toggle are either F (false) or T (true),
and, for the comparison flag, E, G, L (equal, greater, lesser).
'scmp' and 'sover' are setters of the comparison flag and overflow
toggle values.
-- state command: pmem from[-to]
-- state command: smem address value
'pmem' prints the contents of memory cells in the address range
[FROM-TO]. If the upper limit TO is omitted, only the contents of
the memory cell with address FROM is printed, as in
MIX > pmem 3000
3000: + 46 58 00 19 37 (0786957541)
MIX >
The memory contents are displayed both as the set of five MIX bytes
plus sign composing the stored MIX word and, between parenthesis,
the decimal representation of the module of the stored value.
'smem' sets the content of the memory cell with address ADDRESS to
VALUE, expressed as a decimal constant.
File: mdk.info, Node: Configuration commands, Next: Scheme commands, Prev: State commands, Up: Commands
6.2.4 Configuration commands
----------------------------
This section describes commands that allow you to configure the virtual
machine behaviour. This configuration is stored in the MDK directory
'~/.mdk'.
As you can see in their description, some commands print, as a side
effect, informational messages to the standard output (e.g. 'load'
prints a message telling you the loaded program's start address): these
messages can be enabled/disabled using 'slog':
-- config command: slog on|off
Turns on/off the logging of informational messages. Note that
error messages are always displayed, as well as state messages
required using commands prefixed with 'p' ('preg', 'pmem' and the
like).
-- config command: stime on|off
-- config command: ptime
The 'stime' command (un)sets the printing of timing statistics, and
'ptime' prints their current value:
MIX > ptime
Elapsed time: 10 /Total program time: 11 (Total uptime: 11)
MIX >
-- config command: sedit TEMPLATE
-- config command: pedit
'sedit' sets the command to be used to edit MIXAL source files with
the 'edit' command. TEMPLATE must contain the control characters
'%s' to mark the place where the source's file name will be
inserted. For instance, if you type
MIX > sedit emacsclient %s
MIX >
issuing the 'mixvm' command 'edit foo.mixal' will invoke the
operating system command 'emacsclient foo.mixal'.
'pedit' prints the current value of the edit command template.
-- config command: sasm TEMPLATE
-- config command: pasm
'sasm' sets the command to be used to compile MIXAL source files
with the 'compile' command. TEMPLATE must contain the control
characters '%s' to mark the place where the source's file name will
be inserted. For instance, if you type
MIX > sasm mixasm -l %s
MIX >
issuing the 'mixvm' command 'compile foo.mixal' will invoke the
operating system command 'mixasm -l foo.mixal'.
'pasm' prints the current value of the compile command template.
-- config command: sddir DIRNAME
-- config command: pddir
MIX devices (*note Devices::) are implemented as regular files
stored, by default, inside '~/.mdk'. The 'sddir' command lets you
specify an alternative location for storing these device files,
while 'pddir' prints the current device directory.
Finally, you can change the default command prompt, 'MIX > ', using
the 'prompt' command:
-- config command: prompt PROMPT
Changes the command prompt to PROMPT. If you want to include white
space(s) at the end of the new prompt, bracket PROMPT using double
quotes (e.g., 'prompt ">> "').
File: mdk.info, Node: Scheme commands, Prev: Configuration commands, Up: Commands
6.2.5 Scheme commands
---------------------
If you have compiled MDK with 'libguile' support (*note Special
configure flags::), 'mixvm' will start and initialise an embedded Guile
Scheme interpreter when it is invoked. That means that you have at your
disposal, at 'mixvm''s command prompt, all the Scheme primitives
described in *note Using mixguile:: and *note mixguile::, as well as any
other function or hook that you have defined in the initialisation file
'~/.mdk/mixguile.scm'. To evaluate a Scheme function, simply type it at
the 'mixvm' command prompt (see *note Using Scheme in mixvm and gmixvm::
for a sample). Compared to the 'mixguile' program, this has only one
limitation: the expressions used in 'mixvm' cannot span more than one
line. You can get over this inconvenience writing your multiline Scheme
expressions in a file and loading it using the 'scmf' command:
-- scheme command: scmf FILE_NAME
Loads the given Scheme file and evaluates it using the embedded
Guile interpreter.
File: mdk.info, Node: Devices, Prev: Commands, Up: mixvm
6.3 MIX block devices
=====================
The MIX computer comes equipped with a set of block devices for
input-output operations (*note Input-output operators::). 'mixvm'
implements these block devices as disk files, with the exception of
block device no. 19 (typewriter terminal) which is redirected to
standard input/output. When you request an output operation on any
other (output) device, a file named according to the following table
will be created, and the specified MIX words will be written to the file
in binary form (for binary devices) or in ASCII (for char devices).
Files corresponding to input block devices should be created and filled
beforehand to be used by the MIX virtual machine (for input-output
devices this creation can be accomplished by a MIXAL program writing to
the device the required data, or, if you prefer, with your favourite
editor). The device files are stored, by default, in the directory
'~/.mdk'; this location can be changed using the 'mixvm' command
'devdir' (*note Configuration commands::).
_Device_ _No._ _filename_ _type and
block size_
Tape 0-7 'tape[0-7].dev' bin i/o - 100
words
Disks 8-15 'disk[0-7].dev' bin i/o - 100
words
Card reader 16 'cardrd.dev' char in - 16
words
Card writer 17 'cardwr.dev' char out - 16
words
Line printer 18 'printer.dev' char out - 24
words
Terminal 19 'stdin/stdout' char i/o - 14
words
Paper tape 20 'paper.dev' char in - 14
words
Devices of type char are stored as ASCII files, using one line per
block. For instance, since the card reader has blocks of size 16, that
is, 80 characters, it will be emulated by an ASCII file consisting of
lines with length 80. If the reader finds a line with less than the
required number of characters, it pads the memory with zeroes (MIX
character 'space') to complete the block size.
Note that the virtual machine automatically converts between the MIX
and ASCII character encodings, so that you can manipulate char device
files with any ASCII editor. In addition, the reader is not
case-sensitive, i.e., it automatically converts lowercase letters to
their uppercase counterparts (since the MIX character set does not
include the former).
The typewriter (device no. 19) lets you use the standard input and
output in your MIXAL programs. For instance, here is a simple 'echo'
program:
* simple echo program
TERM EQU 19 the typewriter device
BUF EQU 500 input buffer
ORIG 1000
START IN BUF(TERM) read a block (70 chars)
OUT BUF(TERM) write the read chars
HLT
END START
Input lines longer than 70 characters (14 words) are trimmed. On the
other hand, if you type less than a block of characters, whitespace (MIX
character zero) is used as padding.
File: mdk.info, Node: gmixvm, Next: mixguile, Prev: mixvm, Up: Top
7 'gmixvm', the GTK virtual machine
***********************************
This chapter describes the graphical MIX virtual machine emulator
shipped with MDK. In addition to having all the command-oriented
functionalities of the other virtual machines ('mixvm' and 'mixguile'),
'gmixvm' offers you a graphical interface displaying the status of the
virtual machine, the source code of the the downloaded programs and the
contents of the MIX devices.
* Menu:
* Invoking gmixvm::
* MIXVM console:: Using 'mixvm' commands.
* MIX virtual machine:: The MIX virtual machine window.
* MIXAL source view:: Viewing the MIXAL source code.
* MIX devices view:: Device output.
* Menu and status bars:: Available menu commands.
File: mdk.info, Node: Invoking gmixvm, Next: MIXVM console, Prev: gmixvm, Up: gmixvm
7.1 Invoking 'gmixvm'
=====================
If you have built MDK with GTK+ support (*note Installing MDK::), a
graphical front-end for the MIX virtual machine will be available in
your system. You can invoke it by typing
gmixvm [-vhuq] [--version] [--help] [--usage] [--noinit]
at your command prompt, where the options have the following meanings:
-- User Option: -v
-- User Option: --version
Prints version and copyleft information and exits.
-- User Option: -h
-- User Option: --help
-- User Option: -u
-- User Option: --usage
Prints a summary of available options and exits.
-- User Option: -q
-- User Option: --noinit
Do not load the Guile initialisation file '~/.mdk/mixguile.scm' at
startup. This file contains any local Scheme code to be executed
by the embedded Guile interpreter at startup (*note Using Scheme in
mixvm and gmixvm::).
Typing 'gmixvm' or 'gmixvm -q' at your command prompt, the main
window will appear, offering you a graphical interface to run and debug
your MIX programs.
[image src="img/ss_mix.jpg" text="|-----------------------------------------------------------|
| Menu |
|-----------------------------------------------------------|
| |
| |
| |
| |
| MIXVM / MIXAL / Devices |
| |
| |
| |
| |
| |
| |
|-----------------------------------------------------------|
| |
| Command output |
| |
| |
| |
|-----------------------------------------------------------|
| Command prompt |
|-----------------------------------------------------------|
| Status bar |
|-----------------------------------------------------------|
"
|