EDSAC assembler

By anders pearson 04 Feb 2001

for the first two weeks of my Microprocessor Systems Lab class this semester, we were writing machine code for an EDSAC simulator. EDSAC was one of the first true von Neumann machines built in 1949. it had a whopping 2K of memory and 3 registers (an accumulator, multiplier and multiplicand). however, it was a 32-bit architecture (beating Intel by about 40 years).

anyone who’s actually written any machine code before knows that writing anything more than about 10 lines long is tedious and painful. typically, your data (variables, etc) is placed at the end of the program and other instructions access it via it’s relative address. this means that if you insert an instruction somewhere in the middle, your data has moved up a space and you now have to go through your entire program, changing every instruction that accessed data to make it point at the correct address. eg, if you had the following EDSAC code (relative addresses added for clarity):

<br />     GK [sets the relative address base]<br /> 0   ZF<br /> 1   A143@ [add the contents of relative memory location 143 to the accumulator]<br />     ...<br /> 143 PD [an opcode that happens to have the binary value of 1]<br /> EZPF [marks end of program]<br /> 

and you add an instruction after the A143@, you would have to change the A143@ to A144@ as well as increment the address in every other instruction that accessed memory.

knowing that this was going to drive me nuts, i wrote a simple EDSAC assembler that lets you work with variables rather than memory addresses. so now you can just write:

GK 1
ZF 2
O [$figs] <br /> O [$cr]
O [$lf] <br /> A [$n]
TF
A [$here$] <br /> G56F [#print n]<br /> TF [#clear accumulator]<br /> A [$here$]
G88F 3
AF
T [$n] <br /> A [$here$]
G56F 4
5
PD [=n]
#F [=figs]
@F [=cr]
&F [=lf]
EZPF


and it will replace anything that looks like ‘[$variable]’ with the address for the instruction tagged with ‘[=variable]’. it also removes comments (’6’) and handles a special variable ‘[$here$]’ that inserts the current address (useful for calling subroutines via Wheeler jumps in which you have to first put the current location into the accumulator so the subroutine will know where to return to).

i know that EDSAC isn’t quite as popular a platform as, say i386, these days, but somebody might find this useful. i think next i’ll write a C compiler for EDSAC. :)