Files

257 lines
12 KiB
Markdown

## To build:
``` <!---sh-->
make
```
## To use:
``` <!---sh-->
./prog
```
## Try:
To see the original [mullender](../../1984/mullender/index.html) in action:
``` <!---sh-->
./try.sh
```
Observe what happens when you hit enter or another character! You might even try
typing out, one character at a time, `1984/mullender`, and then see what it looks
like at the end. Send INTR to end the program.
More generally use:
``` <!---sh-->
cc -o prog prog.c foo.c
./prog
^C # if necessary, where ^C is ctrl-C, interrrupt
```
to compile and run `prog` as whatever foo.c is in the joke PDP-11 emulator.
## Judges' remarks:
Like [Marty](https://en.wikipedia.org/wiki/Marty_McFly) and
[Doc](https://en.wikipedia.org/wiki/Emmett_Brown), something nostalgic from 1984
appears live in October of 2015!
The author of this gem is a true
[DeLorean](https://en.wikipedia.org/wiki/DeLorean_time_machine)!
A question for inquisitive readers: is the implemented subset of PDP-11
instructions
[Turing-complete](https://en.wikipedia.org/wiki/Turing_completeness)? (For a
clue, see the end of the author's remarks.) If in doubt, use
[APOUT](https://github.com/DoctorWkt/Apout).
## Author's remarks:
### Hint / Compatibility
* A little-endian system is required due to an external factor.
* Strictly speaking, this program does not comply with any C specification for
the same reason. But I believe it is reasonably portable.
* It uses a GCC extension but works with clang.
* This is a kind of emulator. You may find its architecture name if you look at
the source code from all angles..
* Find `main()` function.
### NOTICE to those who wish for a greater challenge:
**If you want a greater challenge, don't read any further**:
just try to understand the program via the source.
If you get stuck, come back and read below for additional hints and information.
### What this entry does:
This program is a joke PDP-11 emulator. ("ll-dpd" is embedded in the code.
Read it upside down.)
You got it? This program is supposed to be used in this way:
``` <!---sh-->
wget https://www.ioccc.org/1984/mullender.c
clang -o prog prog.c mullender.c
./prog
```
You can enjoy the legendary winning entry of the first IOCCC, again.
### How this entry works:
This program uses `__attribute__((constructor))`, which is a GCC extension, to
hijack the `main()` function call. And then it interprets `main()` as an
instruction sequence.
It supports the minimal subset of instructions and addressing modes which are
needed for [mullender.c](%%REPO_URL%%/2015/endoh3/mullender.c) to work:
* Instructions
* BR: branch
* MOV: move
* SOB: subtract one and branch
* SUB: subtract
* TRAP 4: write syscall
* TST: test (no flag is supported, though)
* Addressing modes
* 0: Register
* 1: Register deferred
* 2: Auto-increment
* 4: Auto-decrement deferred
* 6: Index (incomplete)
### Limitations
Non-trivial combination of instruction and addressing mode may cause undefined
behavior (unsequenced modification), such as attempting to auto-increment a
destination register. Index addressing mode works well only for R7 (PC
register).
### One more thing
Note: this program writes a binary file to `stdout`:
```
short main[]={5568,1,-30460,12,2782,0,-29921,2056,-4864,6873,770,30054,11886,
24948,114,21716,-28851,14043,-8944,32691,-16187,-12247,22692,-9781,-20403,
-11771,16546,18710,17873,9233,31304,-32215,-24382,-28247,-25916,10466,24988,
-3404,-4177,-28528,-531,-3016,17300,-28552,-7708,-26180,-4297,-367,-2312,
-25611,28535,-8533,24004,25421,-1224,-5354,-20807,-21589,-6761,-5203,-1055,
-6715,-26673,-1433,-17732,-24198,14681,-3714,-6660,-14891,-25575,20349,-7701,
-8336,31433,16695,-14773,26819,3096,-12584,-28808,17825,-21200,-32399,15877,
-28890,-3728,-27126,21375,-32630,-7615,32004,-29230,-6611,-5508,-28921,12418,
27204,-5725,9643,3520,26836,-29347,2101,-29311,9320,29287,-29990,-6593,29825,
-29114,16232,25641,20672,-23501,-32127,-6546,-956,10474,-29647,1070,5516,13760,
-27814,-32488,-28006,-17968,-3146,10963,19234,22132,23988,7142,5523,9639,-6888,
-11428,7964,23099,-16822,16518,31109,-12958,10351,2434,3091,3625,2244,27512,
-28559,-10724,-19377,23625,30056,11478,-21176,27660,26517,-29037,-9390,12297,
-11903,5980,-21927,-7483,6671,11249,29638,-23827,-26358,-6856,-1063,-5303,
26636,25797,31818,26798,-4243,-18772,-13266,27472,-12005,-10642,-22524,24373,
-13111,-9062,6274,-20002,24150,22189,-14965,-31249,-13934,-6341,-18384,-32054,
-29246,10622,-9260,19428,-15485,2724,23810,16447,11627,18604,2739,27812,30295,
-21538,-31786,11355,-11308,-9006,-4987,25363,-18927,-21130,-31213,-27411,17231,
-19608,20232,27754,16476,11213,-19803,-24048,30918,-25329,21233,-10160,13519,
11828,26653,-6703,10893,6871,-12417,24471,20310,-12137,-19677,4457,-19530,
10147,17724,533,-10055,27076,10264,11274,-10511,4809,25208,16065,-5105,-19953,
3772,-12124,13475,-27559,-9955,26446,15133,15207,-23640,6425,-11010,28688,
-20064,26353,-889,-25008,10380,-14449,-6894,18920,-23900,16902,-31018,16093,
20875,-19576,4585,13126,18589,24789,19424,31274,-5059,-14538,-3125,-16527,
-25070,-9013,26628,15756,-7652,30841,-1283,17707,25717,-18315,-6342,6880,
-19176,6995,5672,2853,-9044,-3409,-14421,-7522,13108,20582,-25317,1376,-5648,
13821,17300,1220,-29437,-25832,-8332,-15575,-9744,28297,31995,-1217,23852,
14382,31059,9160,-3296,20287,-28357,24449,-10323,-21992,-4655,-32548,13237,
-15083,-25226,-21121,2015,-8996,-20247,-27551,-14771,-16089,-6920,-9645,21578,
7142,-5613,14029,24730,-29253,13931,-3862,-16634,-7388,16951,15771,31302,
-22186,-6716,18416,1698,-26200,-16231,9821,-10886,-4994,-30527,-9448,-16923,
29549,-11207,-14909,-3643,-27548,17865,28859,29753,17616,16874,-17733,9424,
21435,-31715,24544,8666,30844,25075,-18267,12027,-5346,2717,19615,-4548,-21763,
28514,11691,22268,-2338,1406,-27379,-23568,-24525,13633,11295,-14715,7877,
-27669,3475,20345,7779,-17849,2184,7132,4079,-24937,11585,22740,5810,-10855,
16203,-6371,23235,-7,-24828,-11205,-11006,-10,-17812,-14274,11504,-27517,463,
4498,-32180,-9775,-3190,-22435,-18662,-30146,-31834,-26449,-19374,-12616,
-10596,14341,-10089,-18449,-16535,21439,21191,-1651,7695,-30009,-23339,-8675,
-20774,21588,-2793,8218,-14337,-10866,14060,-15343,31712,25247,-8539,18074,
-28683,-7363,-7663,-3563,-30718,17771,28687,-30495,30584,14022,-28053,5292,
-31576,-32486,-15470,-1330,23551,-2185,-10829,-13216,-4825,-2964,-14668,24559,
-4930,23731,-1152,-11493,-2321,15987,-27073,-20305,-24065,-25048,32750,-27440,
-1169,-25633,-4356,-24993,30439,-17165,-4580,8662,22655,-4588,-6162,-3122,
31986,-2569,20371,-12320,-25613,-16133,-25644,23677,12254,5855,26325,-13425,
-15903,-1930,-28488,31222,31153,17607,-2758,7594,-8868,30434,-2518,27956,
-19424,7370,6199,-17602,17347,-14358,25588,11611,-25209,-23701,-27444,-29788,
2680,-27406,9318,22483,-28356,28482,4577,-14891,17323,-30152,2507,2977,5004,
-11696,-31623,-15149,13357,28938,-14048,19490,-19860,-26050,10842,-24922,
-20986,8847,-31184,28519,-29168,32195,10516,25713,-3493,670,31283,-12769,
-17461,11357,13180,26133,15944,18051,-32167,-27990,16813,17676,21787,-17578,
11173,19093,2836,656,-15239,4632,23937,4106,-21655,-7494,-21575,-17647,-18465,
-14654,-29990,-10707,-12440,21465,5822,26164,-1404,-14303,-26635,-6900,-23611,
11998,-18551,971,27579,13325,4579,23059,29281,22291,29880,-17546,25664,-14990,
-526,-35,28218,-3214,11965,11263,6633,30719,32400,-29,-3733,24383,32678,-27542,
-4444,6196,5975,-19722,11902,16840,-11680,11146,-26391,-8980,21573,-9043,2349,
-12887,5916,-2996,10410,-23374,26338,11867,-14518,18281,14450,-5815,13842,359,
25450,27043,3355,13423,-20880,-26311,-30720,-2503,-6046,-18156,-18558,-14774,
-15664,-29001,3365,-12689,10233,23608,24692,12039,15445,18411,-27469,3764,
-10841,22672,23844,2282,-12443,2851,-27163,13651,13738,17201,-29819,27414,
-29764,-5308,-16171,-32427,-26312,-7460,-27376,-6004,25717,29254,-15015,8754,
15493,22232,-28513,-23355,23676,7736,10571,-8120,-16677,7696,32549,-2646,25538,
3498,30960,-28459,24716,12655,-10496,402,26209,482,-16661,-20350,-3403,14015,
32299,11262,-25886,4092,-7843,-100,-1975,-58,-3729,-19269,-23583,-6929,20000,
-6089,17780,-3250,29830,19954,-29277,27896,10330,9277,-25358,31279,-14454,
24203,-30170,12872,-21973,-25773,-10502,-6647,-26143,6394,-13479,-24559,23007,
-21844,1505,24702,-23187,-24364,-20470,20765,-7107,15674,9404,17408,17964,
19820,18952,2154,-26052,30056,-3227,17770,-8557,-31018,-27700,-25974,9003,
18218,22730,-19981,6737,3532,1562,-23626,14990,28472,-5270,17358,-32204,-29197,
-3647,4296,8588,25302,-23906,30328,-29119,-24392,8992,-16557,31530,-31216,
14107,13041,-6976,7529,-8296,17865,-1462,8181,-21588,-131,-10177,-25931,-14627,
8301,3708,-32097,20808,13892,-21179,1192,20853,3249,-8774,20843,3520,24954,
-14215,-25170,-16170,2390,25964,-23923,-17464,-7177,-27568,-9880,-4647,-7323,
15388,2113,-12338,-7737,26255,26818,-22156,-19610,-911,-17057,-556,29935,27647,
31806,23676,-18132,-19234,-10869,-3715,24983,-10900,-29564,19856,-16392,-31860,
-25826,24077,12080,15383,-29852,-2266,-27217,31931,-3183,17385,-14211,19050,
-2449,-468,-2871,-11466,973,2866,649,1367,-8688,-24069,20992,25139,-25850,1184,
15851,785,16951,12160,22337,-21851,1849,-18801,14247,-429,-12682,30881,-11273,
-24819,-9794,8389,-27287,7525,16633,1328,-26650,32607,-8217,31912,7774,-16188,
-3546,-6550,-16279,-32696,1940,2577,-23723,-6484,2009,-424,27833,-21763,-13902,
7044,27360,-18450,27889,23987,3137,-7669,-5784,-7490,24946,32302,26464,-15513,
28898,2493,-17645,-4615,-13434,-20884,-4058,-29951,-22281,24784,21083,-8536,
22147,-11261,-15069,20659,2993,19029,21909,6748,-3263,1401,30960,11000,-16871,
-30566,-14959,-26356,-2885,21526,-26531,31063,12857,4992,-5067,3130,-17602,
-1732,-6593,30200,24679,3267,310,20733,24863,-15669,7875,-4577,-13821,-22325,
15548,29744,3733,-14547,21459,22122,3854,-2572,30197,-24770,-21263,8793,-8316,
1571,28191,-16143,-6446,31524,-26496,-17349,-29097,2806,11281,-7041,-683,14149,
19689,-22094,-1657,-30904,183,-15226,-6358,25461,461,1495,28345,-10554,-4004,
27119,13484,-21600,-12272,-7272,-14064,-299,10697,11280,19066,-9841,-7265,
-18002,19906,-17247,21482,-10939,-5897,-22300,-13978,27575,-8684,-6222,-19041,
5788,-30863,-10134,15142,2895,14705,-17713,12940,-21535,-11619,29416,18417,
-24973,24867,-26462,-24910,-32556,-26705,-7187,-7750,-758,-14809,20289,9260,
13778,-1422,30301,-1922,30646,27662,-15465,-912,29340,13846,-1263,28887,-20019,
32421,-29411,-27632,-7495,-8368,29230,-6386,-19536,-5235,2054,1854,23563,12348,
-15165,-2936,-28063,-15760,20126,-25531,4963,-5739,23182,16895,-17258,-10470,
-3969,-7742,-140,4475,-24014,-31961,19231,27153,-18551,20157,26443,11530,
-22214,2284,-24238,-31051,-26422,9088,29868,18458,8488,-9515,6799,-12507,54,
-19441,-32665,12561,23560,4725,-28617,-14800,-10224,-13503,-17636,-16823,
-24072,18735,-29798,-23658,-670,-21769,7489,-6468,-8961,-14785,22255,11582,
-29831,16303,-19652,2922,-4362,22966,16173,-18446,-6148,27381,-8493,-32289,
24005,-3027,-18665,-16472,-17793,-27027,-7443,17854,31365,-17726,-2510,-17546,
14893,21773,-23634,21117,32533,6637,-1106,-8152,-3672,-113,-2149,-34,-22700,
-4102,-28533,-14104,-10086,4378,13695,-15320,-28258,2246,7595,30021,13281,
-11968,-29983,14274,27152,26713,19434,17058,1142,-3043,-16496,18630,-11976,
29168,-3634,32746,27287,-268,16711,-8712,-471,12895,17406,-22548,-3969,-10733,
13128,10530,-31667,7929,-32277,30926,-1983,8401,-7705,6790,4532,1442,26728,
29600,-15358,21622,9744,11406,15989,-30741,-15044,29913,24534,6774,-3755,17623,
19647,18762,10042,9653,-5889,2408,-32579,-6285,-28559,-30655,6294,-21175,4390,
1668,25437,2821,21066,-13680,5274,-27253,-5248,-26307,29744,-26428,25358,17196,
15199,-29784,-4604,25653,-8048,-23131,-28995,31340,-9558,26186,11268,27916,
9646,-7389,-11384,-29116,-4100,160,18394,7856,738,-25920,12148,24713,-31664,
8203,-25556,13494,30352,29161,30898,1432,-5991,25411,1344,-4019,22299,15685,
-16401,-23136,-28110,11874,-18945,1879,2,0,-32256,-20996,-18169,29220,12,0,0,0,
335,-27277,-30776,20480,0};
```
<!--
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
You are free to share and adapt this file under the terms of this license:
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
For more information, see:
https://creativecommons.org/licenses/by-sa/4.0/
-->