Derek Zave's Octal Editor

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.

Notes

  1. To my knowledge, even with all the additional instructions added in the 1108 and 1110, no smaller or faster way to accomplish this conversion was ever found.
  2. On the 1107, every instruction, with the exception of the two MLUs, executed in a single 4.0 microsecond cycle. The MLUs, which reference an additional register, executed in 4.7 microseconds. The 1107 and all its successors had a “barrel shifter”, which allowed shifts of any length to be done in a single cycle.
  3. UNIVAC has been, over the years, a registered trademark of Eckert-Mauchly Computer Corporation, Remington Rand Corporation, Sperry Rand Corporation, Sperry Corporation, and Unisys Corporation. FASTRAND is a trademark of Sperry Rand Corporation, since merged into Unisys Corporation.


Compiled by John Walker
August 13, 1996