4

Is there an assembly simulator in JavaScript available?

If not, would it be feasible and realistic to make one?

Damith
  • 62,401
  • 13
  • 102
  • 153
Linsey
  • 59
  • 2

1 Answers1

6

Yes there is the Javascript PC Emulator

And here there is written what it's emulating: Javascript PC Emulator - Technical Notes

This PC emulator is written in Javascript. The emulated hardware consists in the following devices:

32 bit x86 compatible CPU

8259 Programmble Interrupt Controller

8254 Programmble Interrupt Timer

16450 UART

Real Time Clock.

and

The CPU is close to a 486 compatible x86 without FPU.

Probably the CPU emulator is here: http://bellard.org/jslinux/cpux86-ta.js I've read it's quite simple to read after passing it under a Javascript beautifier, but remember the license!

I haven't watched it (because it's minified and I'm too much lazy to beautify it) but I'm quite sure the real-mode emulator will be minimal, just the strict necessary to bootstrap linux, so I'm not sure you would be able to run a DOS there, and there is the possibility the console has been "bolted" on to connect it to the browser window, so I'm not sure you could have a "real" console. Mmmh... Now I've noticed. It doesn't have a graphical adaptor. It uses the emulated serial port to connect to the browser and show the output. Still the question of the OP was quite precise :-)


I'll add that there is at least a NES emulator written in Javascript. I won't give the URL (just to be sure... These emulators are always at least in the gray line), but its name is jsnes. Now, the NES had a CPU (a Ricoh 2A03 8-bit for the NTSC version and a Ricoh 2A07 8-bit for the PAL version), so the emulator quite surely emulates the CPU :-)

Community
  • 1
  • 1
xanatos
  • 109,618
  • 12
  • 197
  • 280
  • 1
    But all the other answers said it was impossible! – Stefan Kendall Sep 03 '11 at 21:00
  • 1
    @Stefan Once someone told me it was impossible to parse XHTML with Regex. :-) – xanatos Sep 03 '11 at 21:02
  • @xanatos: That on the other hand is indeed impossible, and provably so ;) (Using some of the extensions that push patterns beyond regular grammars, and/or just limiting the goals and accepting failures on some input may work well enough for your particular use case, although it's likely not the easiest solution unless the input is very well-formed.) –  Sep 03 '11 at 21:02
  • A Million Flies Can't Be Wrong... – Janick Bernet Sep 03 '11 at 21:03
  • @Delnan I hadn't told what TYPE of Regex :-) And technically it's only a tokenizer, not a full-blown parser. That is truly impossible considering the DTD. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/5233151#5233151 – xanatos Sep 03 '11 at 21:09
  • @xanatos: That falls under said "Extensions that push patterns beyond regular languages" ;) And again, I'd wager there is little practical benefit, ignoring the challenge (if that's a practical benefit). –  Sep 03 '11 at 21:09
  • @delnan: It's possible if you redefine "regex" from "the regular expressions you learned about in college" to "the extremely complex parsing engine included as a base library in most languages." Can you write a regex to recognize all prime numbers? No? Are you sure? `/^1?$|^(11+?)\1+$/` – Stefan Kendall Sep 03 '11 at 21:12
  • @Stefan: (1) *Of course* it's possible with this thing people call "regex" that isn't "regular". Nobody ever distuted that. Your point being? That we should forget about or invent a new name for the (useful) "simpler" version? No thanks, I'll leave the terms as they are and use new ones for new things. (2) Possible != practical, as we all know - these regex-extensions are in theory powerful enough for highly complex parsing tasks, but most sane programmers would rather use a 100-line recursive descent parser than trying to stuff it all into a 8000 character regex. –  Sep 03 '11 at 21:23