Live data from Hacker News

JSVM

github.com

1–10 of 17 posts

JSVM

#1
Javascript virtual machine is one instruction set machine to parse and execute an assembly like code.

JSVM
github.com

Re: JSVM

#3
Shameless plug: a while back I wrote an assembler-and-VM for a similarly hypothetical assembly language that I was studying in class. Just for kicks, I wondered if I could fit the entire thing into 1KB of JavaScript, whilst including features as step by step execution, a "debugging GUI" (as much as you could expect from 1KB!) featuring the stack, register contents and program counter, plus the assembler on top which performs full syntax/opcode argument checking.

The result (which I'm pretty pleased with) is here: http://chengsun.github.io/ocremutiny.html

Re: JSVM

#4
If I make make a few suggestions (mostly from a desire to see a more familiar sort of spec):

> Add arithmetic shift left/right

> Add logical shift left/right

> Add exclusive OR (XOR)

> Pick a word size so your integer and bit ops have meaning

Questions:

> How do I set the program counter from my assembly?

> Do I have registers (seems like a stack-based VM, so no)? If not, can I have more stacks?

> Can you setup a dedicated block of memory to use as a framebuffer and render it to a tag?

~

Good work so far!

Re: JSVM

#6

I had to write one of these (in C) for a class a couple years ago. https://github.com/tylerkahn/MIPS-Virtual-Machine

Yay MIPS!

Also, let us not forget the Halt and Spontaneously Combust (HSC) instruction: ftp://reports.stanford.edu/pub/cstr/reports/csl/tr/86/289/CSL-TR-86-289.pdf .

Re: JSVM

#7

I had to write one of these (in C) for a class a couple years ago. https://github.com/tylerkahn/MIPS-Virtual-Machine

Whoa dude, this is awesome!

I once wrote a MIPS assembler+VM in Racket. It went OK but I never used it for anything: https://github.com/gcr/mips-simulator Was a great learning experience though.

Re: JSVM

#9
post #8

Better name it VM.js !!

I real disappointed when I discovered this was not an amateur JS vm that I could read in a weekend or two, that would be awesome to have :(

Re: JSVM

#10
Your VM will work much faster if you take the time to do a second pass over the generated "code" and resolve the jumps to LABELs all at once instead of linearly scanning the code for the appropriate target on each jump.
Post reply on HN