Connect with us

Hi, what are you looking for?

Tech & Science

Google Sheets used to create a virtual machine that computes data

Developer Brian Steffens built the virtual machine while experimenting with Google’s Apps Script. Apps Script is built into Google’s online Docs suite and lets you run custom code when events happen in a document.
By crafting Apps Script code, Steffens made a visual representation of a computer processor using spreadsheet cells. The virtual machine has four general purpose registers, used to hold the output of operations, and a 100-cell memory bank which functions as the “computer’s” RAM. There’s also dedicated cells for the instruction and stack pointers that control the execution of “programs.”
Several CPU instructions have been implemented which allow the spreadsheet to operate as a basic computer. It can move memory around the registers, perform operations on data and log any errors that occur during execution. Two sample programs, a factorial generator and a Fibonacci number calculator, demonstrate the computer in action.

Brian Steffens Google Sheets virtual machine

Brian Steffens Google Sheets virtual machine
Brian Steffens


The spreadsheet is designed as a visual introduction to how processors work. You can watch as data is passed between the registers and stored in memory while the program runs. It’s possible to “step” over each line in the code, which runs each instruction individually. This gives you time to watch as the computer performs an operation on its data and then decides what to do it.
Steffens’ post gained popularity this week when it reached the front page of Hacker News. While most users were generally enthusiastic, some criticised Steffens for using Apps Script to build the virtual machine. Critics argued that this oversimplifies the challenge since Apps Script is “basically JavaScript,” a fully-fledged programming language.

Brian Steffens Google Sheets virtual machine

Brian Steffens Google Sheets virtual machine
Brian Steffens


The debate led to Aur Saraf, a Hacker News user known as “SonOfLilit,” setting out to build a spreadsheet-based virtual machine without resorting to using scripts. Dismissing Steffens’ effort as “not an interesting technical accomplishment,” the user returned to Google Docs to create a rival prototype.
The result is a processor simulator that runs entirely using Google Sheets formulas, or the same expressions you’d write in a regular spreadsheet. It can run code written in Brainfk, a simplistic esoteric programming language intended to challenge programmers.
Saraf said that interpreters for other programming languages could be similarly created using a spreadsheet. Brainfk is comparatively complex to interpret so implementations in a different language would be less demanding.
You can view both Steffens’ and Saraf’s spreadsheets over on Google Docs.

Written By

You may also like:

World

Let’s just hope sanity finally gets a word in edgewise.

Tech & Science

The role of AI regulation should be to facilitate innovation.

Social Media

The US House of Representatives will again vote Saturday on a bill that would force TikTok to divest from Chinese parent company ByteDance.

World

Members of the National Guard patrol the streets during an operation to arrest an alleged cartel leader in the Mexican city of Culiacan in...