Programs for the Baby

Programs for the Baby

The Baby The Small Scale Experimental Machine, known as the Baby, was built at Manchester University in 1948. It was one of the first true stored program electronic computers. In honor of its 50th anniversary a replica was built and a programming contest was held. Here is my entry and some other programs. These programs are in the public domain.

Three programs by the method of differences

With only 32 words of memory and only 6 usable instructions it is somewhat challenging to create meaningful programs. It does add and subtract, so one way to make calculations is by iterating difference equations.

Difference Engine

One of the most famous very early computing projects was Babbage's Difference Engine. Here is a simple 4th order difference engine. It uses no programming tricks, just does as many adds as will fit in a loop plus one more to stop it at the end of a run. The difference variables are in the last 4 memory locations. Note that the final variable changes sign 4 times during its run. Source: diffeng.txt.
32			Difference Engine
0000 NUM 0	top:	Temporary storage location
0001 LDN 30		Get 3rd order variable
0002 SUB 31		Add 4th order variable
0003 STO 0		 recomplement
0004 LDN 0		 through temp
0005 STO 31		Store updated 4th order variable
0006 LDN 29		Get 2nd order variable
0007 SUB 30		Add 3rd order variable
0008 STO 0		 recomplement
0009 LDN 0		 through temp
0010 STO 30		Store updated 3rd order variable
0011 LDN 28		Get 1st order variable
0012 SUB 29		Add 2nd order variable
0013 STO 0		 recomplement
0014 LDN 0		 through temp
0015 STO 29		Store updated 2nd order variable
0016 LDN 27		Get 0th order variable (constant -1)
0017 SUB 28		Add 1st order variable
0018 STO 0		 recomplement
0019 LDN 0		 through temp
0020 STO 28		Store updated 1st order variable
0021 SUB 26		Subtract final value
0022 CMP		Test for equality
0023 JMP 25		Jump back to top if still greater
0024 STP		Stop
0025 NUM 0		Indirect jump value
0026 NUM -669		Final value of 1st order variable
0027 NUM -1		0th order variable (constant -1)
0028 NUM 669		1st order variable
0029 NUM -189363	2nd order variable
0030 NUM 26199102 	3rd order variable
0031 NUM -600000000	4th order variable

Artillery Game

The famous ENIAC electronic calculator was designed to do ballistics calculations, among other things. Here is a tiny version of the old artillery game, where you choose the initial velocity of a projectile and try to hit a target. In this version the X and Y components of the initial velocity go in locations 29 and 28 and initial X and Y displacement from the target in locations 31 and 30. During the run X and Y track the progress of the projectile and at the end (when Y crosses below zero) the final X value in location 31 shows you how close you came. Source: artillry.txt.
32			Artillery Game
0000 NUM 0		Standard filler, constant 0
0001 LDN 0	top:	Load 0
0002 STO 30		Initialize Y (vertical) position
0003 LDN 19		Load negative range
0004 STO 31		Initialize X (horizontal) position
0005 LDN 31	loop:	Get X position
0006 SUB 29		Add X velocity
0007 STO 26		 recomplement
0008 LDN 26		 through temp
0009 STO 31		Store updated X position
0010 LDN 30		Get Y position
0011 SUB 28		Add Y velocity
0012 STO 26		 recomplement
0013 LDN 26		 through temp
0014 STO 30		Store updated Y position
0015 CMP		Test for negative (fell back through 0)
0016 JMP 19		Jump ahead if still going
0017 STP		Stop
0018 JMP 0		Jump to top for another round
0019 NUM 8388627	Initial range and jump constant 19
0020 LDN 28		Get Y velocity
0021 STO 26		 recomplement
0022 LDN 26		 through temp
0023 SUB 27		Subtract gravity constant
0024 STO 28		Store updated Y velocity
0025 JMP 27		Jump back to loop
0026 NUM 0		Temporary variable
0027 NUM 4		Gravity constant and jump constant for loop
0028 NUM 4095		Y Velocity - adjust between rounds to aim
0029 NUM 4095		X Velocity - adjust between rounds to aim
0030 NUM 0		Y Position
0031 NUM 0		X Position

4-quadrant Sine Calculation

The Baby can do trigonometry. Here is a program which approximates the sine of any angle from 5 to 320 degrees in 5-degree increments (with these parameters it doesn't quite make it all the way around.) The initial angle goes in bits 7-12 of location 28 and the answer appears in location 31 with the binary point above bit 15. As shown here it calculates the sine of 135 degrees yielding the square root of two.

The program uses several tricks to fit in memory. The indirect jump value at 0 for the inner loop is strategically located so that the jump instruction at 15 is used four different ways - as an instruction, as the indirect jump value for the outer loop, as the decrement for the outer loop counter and as unity (virtual "one") for all the arithmetic in the program. The outer loop jump "JMP 15" at 28 also holds the outer loop count. When the count expires the opcode changes from jump to stop. Finally, the scaling constant at 25 is encoded in the "LDN 28" instruction there, including the op code.

With other scaling constants the program can achive higher precision and accuracy as well as handle larger angles at the cost of significantly increased run time. The parameters here are a compromise to show interesting angles within a reasonable run time. Source: sine.txt.

32			Sin(x)
0000 NUM 3
0001 LDN 30	major:	Get cosine
0002 STO 29		Put in dividend
0003 STO 30		Store cosine positive
0004 LDN 31	minor:	Get sine
0005 SUB 15		Increment using u
0006 STO 31		 recomplement
0007 LDN 31		 in place
0008 STO 31		Store incremented sine
0009 LDN 29		Get dividend
0010 STO 29		 recomplement
0011 LDN 29		 in place
0012 SUB 25		Subtract divisor
0013 STO 29		Store updated dividend
0014 CMP		Skip if division complete
0015 NUM 128	u:	JMP 0 to minor loop if not (3 other uses)
0016 LDN 31		Get sine
0017 STO 29		 recomplement
0018 LDN 29		 in dividend (temporary)
0019 SUB 25		Subtract divisor to rezero
0020 STO 31		Store adjusted sine
0021 SUB 30		Negative subtract cosine
0022 STO 30		Store updated cosine negative
0023 LDN 28		Get x
0024 STO 28		 recomplement
0025 NUM 16796		 in place (this LDN 28 also used as divisor)
0026 SUB 15		Decrement x using u
0027 STO 28		Store updated x, x changes to STP on underflow
0028 NUM 3343	x:	JMP 15 through u to major loop, also contains x
0029 NUM 0		Dividend for scaling down cosine variable
0030 NUM -3695104	Cosine variable (negative)
0031 NUM 0		Sine variable

Back to Paul's Home Page