Thursday, October 07, 2010

The Analytical Engine vs. The ZX81

Many people got started with computing in my age group with the Sinclair ZX81 (which in the US was sold as the Timex Sinclair 1000).

Reading through Allan Bromley's excellent papers on Babbage's Analytical Engine (as described in 1847) I thought it might be fun to compare the two machines.

The ZX81 has 1KB of memory in which programs and data had to be stored. The Analytical Engine as first imagined would have had 50 variables capable of each storing a 30 digit decimal number. That's equivalent to each variable having 100 bits and hence the memory for the Analytical Engine would have been 5000 bits (675 bytes). Later Babbage proposed much larger memory sizes with up to 50 decimal digits per variables and 1000 variables: that would have been a memory of 166 bits per variable or over 20 KB of memory.

Critically, the Analytical Engine's programs would be stored on punched cards and executed directly from them so that entire memory space was for data (not the program). In contrast the ZX81 had to load the program from magnetic tape into its 1KB of RAM.

But the ZX81 was much, much faster than Babbage's machine. It had a clock speed of 3.25 MHz. The Analytical Engine was based around a standard cycle time of 1/7s which is the same as 7Hz. To get an idea of the speed of the machines, here's a comparison of a 100 bit add on the two machines.

On the Analytical Engine it would take about three seconds to fetch the two numbers from memory (the store) and perform the addition. Although this is long Babbage added the ability to do a pipeline of multiple additions with overlapped reads from memory and addition happened in parallel. The ZX81 does not have that ability.

On the ZX81 in Z80 assembler a 100 bit addition (which I've done as 13 8-bit additions here) could be implemented as follows. I've assumed that IX and IY are pointing to the operands in memory and that the result will be stored in the memory addressed by IY.

LD A,(IX+0)
ADD A,(IY+0)
LD (IY+0),A
LD A,(IX+1)
ADC A,(IY+1)
LD (IY+1),A
LD A,(IX+2)
ADC A,(IY+2)
LD (IY+2),A


LD A,(IX+12)
ADC A,(IY+12)
LD (IY+12),A

Each instruction there takes 19 clock cycles and there are a total of 39 instructions giving 741 clock cycles. With the Z80 running at 3.25MHz that set of instructions takes 0.228 ms. So for that addition the ZX81 would have been 13,000x faster.

Obviously, this is slightly bogus because there are other more complex and slow instructions in the Analytical Engine (such as division) but it gives an idea of the scale.

So, the ZX81 had much less RAM than the Analytical Engine (and who doesn't remember all the trouble of fitting everything into RAM on those machines) and was forced to use it to hold programs, but the Analytical Engine was slow in comparison.

PS If you'd like to see the Analytical Engine built, read this.


aglemann said...

"So, the ZX81 had much less RAM than the Analytical Engine"

I thought I read from your description that the ZX81 had 1KB of RAM and the AE 0.375KB - am I missing something?

John Graham-Cumming said...

I was comparing the AE proposed top memory of 20KB with the ZX81's 1KB. I will modify the text to make that clearer.

Anonymous said...

Indexed instructions are fairly slow, so it'd be faster switching to using DE+HL instead of IX+IY.


7+7+7+6+6=26T compared to 19+19+19=57T for the index register method – twice as fast!

You can save a further 4T by incrementing only the low byte of the pair, if the values are arranged so they don't span 256-byte boundaries.

Unknown said...

You could get a 16KB RAM expansion pack for the ZX81 for about £50 (and you could play 3D Monster Maze on it too)

Carlos Valiente said...

"In contrast the ZX81 had to load the program from magnetic tape[..]"

..for those of you whose elder brother let you use his tape recorded -- I had to type my programs a la Babbage :-)

Richard Jones said...

Actually the Z80 did some very simple pipelining. It was able to overlap the fetch of the next instruction while retiring the previous instruction.


Unknown said...

Babbage invented pipelining? In the 1840’s? Wow, incredible. Genius. (

Kurtkilgor said...
This comment has been removed by the author.
Lutyens said...

The ZX81 had to use the 1KB for the display file too, so even basic AE may have had more memory. If you plug in the 16KB RAM pack, lots of memory, but did the Analytical Engine have an equivalent of the Ram pack wobble problem?

CodeMonkey said...

I feel the analytical engine is being undersold here. The Z80 add you show is in binary, the AE does a 2x50 digit addition in BCD. My quick attempt at a 50 + 50 BCD addition on a 3.25MHz Z80 is 0.5ms. I think the AE can do it in 4 cards:
Load Store to Mill
Load Store to Mill
Load Mill to Store
If that is 4 cycles @ 7Hz= 0.57s
The Z80 is "only" 1124 times faster
If the AE performs a multiplication in the same time as an addition (I am trying to find this out) I think the AE possibly could beat the Z80 here!!!
Now how about division, that is more complex/slower than multiplication.
Again how many cycles does the AE take to do a division?

CodeMonkey said...

Curses I am undone!
The AE is (of course) multicyclic on multiplications and divisions.
Babbage had invented some clever look ahead mechanics but it looks like it would still take 59 cycles @ 7Hz ie 8.5 seconds to do a 50 x 50 decimal multiplication. The Z80 is going to beat it.
HOWEVER what about comparing it to the "first" microprocessor- the Intel 4040........