# ProjectEuler Problem 1 in IAS Machine Code

The IAS Machine was the first electronic computer built at the Institute of Advanced Studies (hence the name) at Princeton. The leader of the project was John Von Neumann, who was also a consultant at the ENIAC project (the first general purpose electronic computer). The IAS project was quite important because it was one of the first computers to implement the concept of “stored program”, where the instructions of programs would be stored in memory, alongside with data. This model made it much easier to store and edit programs, and it also made possible for the program itself be changed at execution time, making it easier to work with branches and arrays of data. You can read more about it on Wikipedia.

The architecture of the IAS was very simply, yet very efficient. So much that it became known as the “Von Neumann” architecture, and it’s the base for pretty much all modern computers, including the one you are using right now. The IAS Machine had 1024 memory addresses, each 40 bits long. Each instruction occupied 20 bits, where the first 8 bits were the opcode and the remaining 12 bits were the address parameter.

There were only 20 instructions, and you can see them on this PDF.

The interesting thing about programming for the IAS is that given the simplicity and reduced amount of instructions you can write machine code directly. Below you’ll find my solution to problem 1 on Project Euler in IAS machine code. I wrote in hexadecimal instead of binary to save space, but it’s the same thing really. You will need an IAS simulator/emulator to run the code, but there are a bunch of those available online.

The problem:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

The solution:

``````000 01102 0C100
001 21105 02105
002 10005 01102
003 0C101 21105
004 02105 10005
005 0D007 01103
006 05102 21103
007 01102 05099
008 21102 01104
009 06102 0F000
00A 01103 0D400
...
099 0000000001
100 0000000003
101 0000000005
102 0000000003
103 0000000000
104 00000003E7 ``````

## One thought on “ProjectEuler Problem 1 in IAS Machine Code”

1. Salana

Hey,

I was studying this and just had a question with the sequence of instructions. Will your program be executed
1L -> 1R ->2L ->2R …..etc
Example with reference to program above:
1. 01102
2. 0C100
3. 21105
.
.
. and so on

I know that there are specific instructions which tell it to load left or right instruction. However how is it executed by default when no specific JMP instruction is supplied ?