[Demo of calculating a constant in an interlude at load time. EDSAC program, Initial Orders 2.] [Arrange the storage] T46K P56F [N parameter: library subroutine P7 to print integer] T47K P100F [M parameter: main routine] E25K TM GK [M parameter, main routine] T#Z PF [clear 35-bit value at relative locations 0 & 1, including the middle ("sandwich") bit] T2#Z PF [same for 2 & 3] T4#Z PF [same for 4 & 5] TZ [resume normal loading at relative location 0] [Storage for interlude, must be at even address] [0] PD PF [35-bit factorial, initially integer 1] [2] PD PF [35-bit factor 1..10, initially integer 1] [4] PF K4096F [to save multiplier register (MR), initially floating point -1] [6] PD [17-bit integer 1] [7] P5F [17-bit integer 10 (or number whose factorial is required)] [8] PF [dump for clearing acc] [Executable code for interlude; here with acc = 0] [9] N4#@ [acc := MR, by subtracting (-1 * MR)] T4#@ [save MR over interlude] [11] T8@ [start of loop: clear acc] A2@ [acc := factor] A6@ [add 1] T2@ [update factor, clear acc] H2#@ [MR := factor, extended to 35 bits] V#@ [times 35-bit product, result in acc] L1024F L1024F L256F [integer scaling: shift 34 left] T#@ [update product] A2@ [acc := factor just used] S7@ [is it 10 yet?] G11@ [if not, loop back] H4#@ [restore MR before exit from interlude] E25F [pass control back to initial orders] [At this point the interlude has been loaded but not executed. The next control combination starts execution.] E9Z [pass control to relative location 9 above] PF [value in accumulator when control is passed: here = 0] [After the interlude, loading resumes here.] T2Z [resume normal loading at relative location 2, overwriting the above interlude except the factorial] [Teleprinter characters] [2] #F [set figures mode] [3] @F [carriage return] [4] &F [line feed] [Enter here with acc = 0] [5] O2@ [set teleprinter to figures] A#@ [acc := factorial, as calculated in the interlude] TD [pass to print subroutine] [8] A8@ GN [call print subroutine] O3@ O4@ [print CR, LF] O2@ [dummy character to flush teleprinter buffer] ZF [stop] E25K TN [N parameter] [Library subroutine P7, prints 35-bit strictly positive integer in 0D.] [10 characters, right justified, padded left with spaces.] [Even address; 35 storage locations; working position 4D.] GKA3FT26@H28#@NDYFLDT4DS27@TFH8@S8@T1FV4DAFG31@SFLDUFOFFFSF L4FT4DA1FA27@G11@XFT28#ZPFT27ZP1024FP610D@524D!FO30@SFL8FE22@ E25K TM GK [M parameter again] E5Z [define entry point] PF [acc = 0 on entry]