At some point in his career, almost every UNIVAC® systems programmer stumbled over the following fragment of code, originally written by Derek A. Zave for the UNIVAC 1107 at Case Institute of Technology. The UNIVAC instruction set may seem eccentric by contemporary standards, but in the hands of a master amazing things could be accomplished with very few instructions. The following code takes a 36 bit binary number in register A13 (any three consecutive A registers could be used) and, in 12 instructions, with no loops or conditional tests, and using only instructions from the 1107 set, hence no double register loads and stores and no left shifts, emits in registers A14 and A15, the number edited into FIELDATA code, ready to be sent to the printer. The input in A13 is not destroyed, and the only other register used is R2, the hardware-defined mask register for the Masked Load Upper (MLU) instructions. No temporary storage is used, allowing any number of CPUs to safely execute the code simultaneously.
Here's a listing of Derek's editor, in SLEUTH II, later referred to as just UNIVAC 1100 series assembly language. A leading zero on a number denotes an octal constant, and single quotes denote text constants in the FIELDATA character code. Values enclosed in parentheses are literals which the assembler places in a separate table in the data section of the program. In the comments, the arbitrary input number is represented as ABCDEFGHIJKL, and the contents of the emerging result in registers A14 and A15 which result from each instruction are shown to the right.
. A13 A14 A15 L A13,(Number to be edited) AND A13,(0707070707070) . ABCDEFGHIJKL A_C_E_G_I_K_ xxxxxxxxxxxx SSC A14,36-3 . ABCDEFGHIJKL _C_E_G_I_K_A xxxxxxxxxxxx A A14,('000000') . ABCDEFGHIJKL 6C6E6G6I6K6A xxxxxxxxxxxx L R2,(0000700070007) . ABCDEFGHIJKL 6C6E6G6I6K6A xxxxxxxxxxxx MLU A14,A13 . ABCDEFGHIJKL 6C6E6G6I6K6A 6C6D6G6H6K6L L R2,(0707770777077) . ABCDEFGHIJKL 6C6E6G6I6K6A 6C6D6G6H6K6L MLU A13,A14 . ABCDEFGHIJKL 6B6E6F6I6J6A 6C6D6G6H6K6L SSC A14,36-6 . ABCDEFGHIJKL 6E6F6I6J6A6B 6C6D6G6H6K6L DSC A14,72-24 . ABCDEFGHIJKL 6A6B6C6D6G6H 6K6L6E6F6I6J SSC A15,12 . ABCDEFGHIJKL 6A6B6C6D6G6H 6I6J6K6L6E6F DSC A14,12 . ABCDEFGHIJKL 6E6F6A6B6C6D 6G6H6I6J6K6L SSC A14,36-12 . ABCDEFGHIJKL 6A6B6C6D6E6F 6G6H6I6J6K6L
Special thanks to John Langner, who found a copy of this program in his archives and passed it on for inclusion here.