Virtual CPU Stays On Script

Some will see it as a great thing, and others as an example of how JavaScript is being abused daily, but [Francis Stokes] decided to design his own CPU architecture and implemented a virtual version of it using JavaScript. The CPU is a 16-bit affair and has a simplified assembly language. The code is on GitHub, but the real value is [Francis’] exposition of the design in the original post.

While discussing the design, [Francis] reveals his first pass at the instruction set, discussed what he found wrong about it, and then reveals the final set composed of real instructions and some macros to handle other common cases.

[Francis] got the CPU bug from watching [Ben Eater’s] videos. Of course, [Ben’s] CPU is 8-bit and lives on a breadboard. If we had wanted to test out a new instruction set architecture, we would probably use C or C++ or… well, honestly, anything but JavaScript. But if there’s one thing we’ve learned is that everyone’s tastes are different. We have no doubt, though, there will be some spirited comments on both sides.

Developing CPUs for sport has become almost popular these days. Of course, few have the surrounding environment that A2Z does.

16 thoughts on “Virtual CPU Stays On Script

  1. I won’t start any language wars here (I kinda like Javascript frankly), but I am starting to wonder if Javascript is becoming the lingua franca of the new generation of programmers. In other words everyone knows javascript these days and it is the first thing people think of reaching for — which is just fine by me. All very cool.

    1. Ugh… I do not want to start a war here. But we used it in production (sort of). The issue (with a browser and general tools)… I have seen 60%-80% of one core on J1900 taken by…. scrolling one text field back and forth in jquery + javascript.

      Add here issues along the lines of “oh, I mistyped and now it is a new variable” or certain language “features” due to the way it has evolved and not planned…
      I read it, I can write small things in it. But liking JavaScript? Heaven forbid. There are much better languages out there.

  2. Like it or hate it, JavaScript is the only language available today on ALL computers, smartphones and tablets connected to the Internet, right in your browser!

    And you have accordingly millions of script monkeys that are using it think of it as the new Visual Basic language, for good or bad.

    You even have now WebAssembly that provides a standard low-level cross-browser stack-based VM: https://en.wikipedia.org/wiki/WebAssembly

    1. It’s not the only language. In fact it is often implemented in yet another high level language which may and may not be a layer on top of another high level language.

      This is a case where I read these comments and I have to wonder if the person posting them understands what JavaScript actually is in the first place.

      Me personally I would rather work with C even though it lacks a lot of the modern language features I’ve come to love.

  3. Eh. Javascript is a programming language; a programming language is for programming and as long as you’re using it for that it can’t be “abused” per se. The language you’ve chosen may be less optimal than some others, it may be so obscure that only a few others can even read your code, but as long as it gets the job done it totally fulfills its purpose. Javascript is so common nowadays that most programmers can grasp Francis Stokes’s code, so the choice of language is perfectly appropriate even from the point of sharing it with the wider public.

    1. I think the criteria “gets the job done” is no longer catered for. It just needs to approximate the task and never mind what else it does that it shouldn’t because you can spend the next five years issuing updates that you get paid for then scrap it and release a whole new one with different problems.

  4. I have used Javascript for a long time now to define, develop and refine the YASEP microcontroller.
    I ended up creating a whole framework with windows and bells and whistles !
    http://archives.yasep.org/yasep2014/
    Features among others : documentation,assembler, disassembler, simulator, configurator, save/restore, video framebuffer…
    Please help me and contact me so I can spin the whole thing off and make it CPU-agnostic !

  5. Just BLOCK all scripting in your browser. The script blocker (there are many) will EXPOSE just how bad Javascript is being abused by Web-sites on the Internet today – mostly for MONEY! Just remember to choose a script blocker that has a fairly honest user acceptable white/black list (immediately delete ALL the white-listed entries, and keep an eye on the list). Also, keep an eye on your “host” file (and which “host” file is actually being used). Is this an air-tight solution – Nah – NOTHING is air-tight on the Internet these days.

  6. Very cool project. But does lack (from a quick scan of the instruction set) one of the most important but most misunderstood instructions, the exchange instruction. This will exchange two values, one in a register and one in ram in a single cycle (last bit very important). Without it you can not do reliable semaphores with external hardware or thread synchronising.

Leave a Reply

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.