Hacker News new | past | comments | ask | show | jobs | submit login
Mini x86 – An x86 documentation, decompiler and emulator in pure JS (github.com/xem)
84 points by matt_d on Dec 31, 2016 | hide | past | favorite | 15 comments



Hi guyz, I'm the author of this project, but not the author of this post. Indeed the project is very incomplete and indeed it's "disassembler" - not "decompiler" :) I plan to talk about it on HN when I'm satisfied with the results (and when the emulator starts outputting things)... today was a little early.

Thanks though for the upvotes and the kind remarks!

Cheers and happy 2017!


TLDR:

* There is no emulator

* This appears to be a work-in-progress project.

* The 'decompiler' is actually a disassembler

* Only supports a tiny subset of opcodes.


This is fantastic! I wish this existed back when I did my emulator-baked remakes experiment [1]. May use this as the foundation for the next iteration!

[1] http://gabrielgambetta.com/remakes.html


It seems nice, but the actual disassembler doesn't seem to work here:

http://xem.github.io/minix86/decompiler.html

is there any specific browser or OS requisite?

The "choose file" button works, but then nothing happens, and all the "built-in" examples buttons do nothing.


it should work on any modern browser. Warning though, the url has changed a little: see https://github.com/xem/minix86


Ok, still this:

https://xem.github.io/minix86/src/disassembler.html

doesn't work for me, maybe by "modern" you mean a current Chrome or Firefox.

I tested it with QTweb, Chrome 43 and Opera (Presto), certainly not the most "mainstream" or "popular" or "latest" browsers around, still I find no real reason why the thingy shouldn't work with them.


I just tested on Chrome, Firefox and Edge (W10) and it works fine everywhere. Do you have an error showing up in your console or something?


In Chrome 43 (Ok, Iron Browser) I get two errors:

Uncaught SyntaxError: Unexpected token =>helpers.js:10

Uncaught SyntaxError: Unexpected token =>demos.js:2

Basically the first two actual instructions are not parsed correctly.

In Opera (12.15) I have three errors:

Syntax error at line 10 while loading: expected expression, got '>' var to16 = (n, l) => { -------------------^ Linked script compilation helpers.js Syntax error at line 38 while loading: invalid character after numeric literal: 'b'. n = b & 0b1111; -------------^ Linked script compilation disassembler.js Syntax error at line 2 while loading: expected expression, got '>' hello.onclick = e => { -------------------^ Linked script compilation demos.js


[deleted]


the real challenge is implementing the sheer amount of opcodes

If you want to write the most compact emulator, not necessarily the fastest, you can use the octal structure of the instruction encoding to condense your code greatly.

https://news.ycombinator.com/item?id=13045558

The first ~1/4 of the first-page opcode space is ALU ops, the next 1/4 is inc/dec/push/pop reg. The second half is less regular but you can still find big chunks that can be taken care of with only a few lines of code (e.g. 9x are exchanges with eAX, Bx are all immediate moves.)


Indeed, the final goal is to make it compact too. Thanks for the link! Another source of inspiration for compactness is: https://github.com/adriancable/8086tiny


This is not a decompiler but a disassembler. See[0] for futher details.

[0]: https://en.wikipedia.org/wiki/Decompiler


I was also a bit disappointed to see that, since a decompiler is far more interesting (and complex). But decompilation involves disassembly (in particular, one that follows the execution flow) so at least it's a start...

As discussed at https://news.ycombinator.com/item?id=9321698 , "write a disassembler at least once" is a good exercise and not particularly hard even for x86, because a lot of the instructions follow common patterns (easier to see in octal.)


Why use Javascript for this?


Atwood's Law [1] ... Mainly because the web browser is the single most broadly available interface with JS being the most accessible language to use in that interface. There are definitely other JS x86 emulators out there. JS isn't the fastest available, but it's far closer to run everywhere.

[1] https://blog.codinghorror.com/the-principle-of-least-power/


Mainly for fun and because I like this language. Also, my goal is to let people drop a x86 demo in their browser and just watch it play or interact with it without any other tool.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: