# Writing A Virtual Machine In Excel

[Ádám] participates in a competition called KöMaL. It’s a 9-times-a-month journal for junior high and high school students featuring math and physics problems. [Paul Erdős], one of the most published mathematicians of all time, was a huge participant and by far the most notable student to crack open a copy of KöMaL in its hundred-year history. [Ádám] was trying his hand at a problem in Excel, but the official rules prohibit the use of Excel macros. In a daze, he came up with one of the most clever uses of Excel: building an assembly interpreter with the most popular spreadsheet program.

This is a virtual Harvard architecture machine without writable RAM; the stack is only lots and lots of IFs.  The instructions – mostly load, MOV, JNZ, INC, and CMP solves this problem, examining two inputs to see if they multiples of each other. If you’re wondering, an example cell from [Ádám]’s Excel sheet looks like this:

```=F6
INDEX(\$C\$2:\$C99999,\$G2,1),
IF(AND(INDEX(\$B\$2:\$B99999,\$G2,1)="JZ",\$I2=0),
INDEX(\$C\$2:\$C99999,\$G2,1),
IF(AND(INDEX(\$B\$2:\$B99999,\$G2,1)="JNZ",\$I2<>0),
INDEX(\$C\$2:\$C99999,\$G2,1),
G2+1
)
)
)
)```

[Ádám] has provided his Excel solution to the problem, available on the hackaday.io. It’s in Hungarian which really shouldn’t matter since it’s basically Excel and a pseudo-x86 instruction set. but the column labels will require a bit of Google Translate.

## 26 thoughts on “Writing A Virtual Machine In Excel”

1. Kryptylomese says:

One day soon, Excel itself will be written in this way…..

1. Andy says:

Many people in engineering working on replacing SAP & SQL with Excel.

ASk 5 Times “Why”, and the third “why” will be “because there was an error in the Excel sheet”

1. Zac says:

As someone currently working on a SAP integration, I would happily give my left testicle to not have to see it ever again.

1. Michel says:

You sir, are so right.

2. lol says:

LOL!!!!!!!!!!

2. Voxnulla says:

I teach my peers that everytime you use excel, a puppy dies.

1. Evad says:

What do you use for a spreadsheet, or do you just keep all the math in your head?

1. voxnulla says:

I live by the rule that generally you can solve most problems, at minimum, two ways. One is utilizing excel and the other is doing it the right way with the right tool.
If you think you need excel, you are simply unaware of the right tools and methods, ergo not qualified to handle the subject and should therefor be shot (if continuing insisting to use excel).

1. ekerin says:

Might I propose a thought exercise.

Without answering never – When IS a spreadsheet the right tool for the job?

1. CodeRed says:

Ad hoc data manipulation and simple reporting. One off kinda stuff. At my office, anything that is simple enough that the business user can handle it without involving IT, otherwise it has to go though the code release process (public company, SOX control type stuff).
The main problem is when it becomes part of the business process. Stuff outside of source control with tricky insecure DB password setups, that only that one guy knows how it worked.

2. voxnulla says:

Never… ever

3. Autunite says:

For playing EVE online

2. OtherPeople says:

Excel is like the Arduino of the business world.

3. Karsten Becker says:

I fail to see why that got the harvard architecture tag ;)

1. abecedarian says:

Because it can read an instruction AND data simultaneously?

1. prog_algo says:

Where the !@#\$ is the “Like” button?! This phrase is ridiculously funny, I don’t know why.

4. andrew says:

This strikes me as a reasonable way of teaching assembly

1. Voxnulla says:

You mean if you lack any sort of editor and an assembler which is never? It is never reasonable to suggest that excel has any benifitnat all, but this is blassm’phemy.

5. This is some masochist level shit right here.

6. Ragnar says:

Do I see this right, to download this I need to be part of a “Social”-Network?

7. Martin Haeberli says:

Ironically, Excel is written in a C dialect itself called “Hungarian” after its architect and former Microsoft employee, Charles Simonyi. Look it up for more of the back story.

8. Rollyn01 says:

And here I thought this was about a FSM coded through Excel.

9. Late on this, but I once found an implementation of a back-prop ANN for Excel…

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.