We Made 8086 Emulator In Rust and Integrated it with React using WASM 
Tags: showdev, rust, react
Published: 2021-01-01 15:21:18

![Commandline](https://dev-to-uploads.s3.amazonaws.com/i/srl8lf9uxhbfvr3vipq1.png)

# Short Version
We made an Intel 8086 Emulator in Rust. The commandline version is at : [https://github.com/YJDoc2/8086-Emulator](https://github.com/YJDoc2/8086-emulator). Then we compiled it to WASM and integrated with React to make a front-end only 8086 Emulator website. Repository is [https://github.com/YJDoc2/8086-Emulator-Web/](https://github.com/YJDoc2/8086-Emulator-Web/). It is hosted on GitHub pages at : [https://yjdoc2.github.io/8086-emulator-web/](https://yjdoc2.github.io/8086-emulator-web/).
Please check it out, and let us know how it is. If you think it is interesting, please start the repos :smile:

Phew! Now for the long version.
# What ?
In my recent semester we had Microprocessors as a subject, and more than half of it was based on Intel 8086 microprocessor. Now usually when the labs for this were taken, one would probably use some kind of kits or such to write programs of 8086 instruction set x86 assembly, and test it out. But... as this time it was conducted online, we had to use something else. Now the emulator we were supposed to use , in my opinion , had some issues.
* It had to be downloaded as binary from a site, which is not necessarily dangerous, but can give off some virus or malware
* It was only available for Windows and Mac

along with this it had some other issues as well.

# So then?
  While searching for some other 8086 emulator to use, I came across [https://schweigi.github.io/assembler-simulator/](https://schweigi.github.io/assembler-simulator/), which is a 8085 emulator. This seemed a really cool thing, made in Angular and using JS to run the assembly. (Check it out as well, it is quite cool!)
But other than that, I couldn't find a 8086 emulator.

# And then...
![Pheneas And Ferb I Know What We're Gonna Do Today](https://dev-to-uploads.s3.amazonaws.com/i/c9sgas1ues5now2ulyyn.gif)
I decided to make one :nerd_face: :sunglasses: I am interested in compilers, (check my c-to-assembly blog series [here](https://dev.to/yjdoc2/looking-under-the-hood-learning-assembly-by-compiling-c-102o)) and this seemed like a good place to actually use my interest in compilers,the microprocessors course I took, and Rust.

# Then ?
![Phineas And Ferb Whiteboard](https://dev-to-uploads.s3.amazonaws.com/i/u278safhenshvvsu1dnr.png)
As I had seen the 8085 emulator, it seemed a pretty good idea to make mine also in web version, but I didn't want to write complete Lexer and parser part in JS. As I also wanted to make a commandline version as well, the best Option seemed to be making a core library in Rust and then make different interfaces for both version, compile Web version to WASM and integrate it with front-end. And (bad Rust pun ahead..) that turned to be Some(Emulator) :sweat_smile:

# Cool, So now ?
So, my friends and me went ahead, and made the core library, the 'drivers' (interfaces for both versions) and the React frontend, compiled Rust code to WASM, tries to integrate them, found bugs in code, fixed bugs in code ;  Rinse and repeat few more times, and got ourselves an 8086 emulator :partying_face: :tada: 
![Phineas And Ferb Dancing](https://dev-to-uploads.s3.amazonaws.com/i/n6k7iy0bqr3rqttsdoq8.gif)

# And what does it do ?
![Phineas And Ferb What does it Do](https://dev-to-uploads.s3.amazonaws.com/i/45ilmc4lrknyi1e3b0oj.png)

Ok, so hopefully it does not crash into your front yard, beeping.

Both versions allow most of the instruction set of 8086 assembly, with exceptions of few instructions used to interface with external devices or so, and only allows selected few interrupts, as it does not store the instructions in memory which is required by Interrupt Service Routines. It gives complete 1 MB Memory to store data, and access to all registers which 8086 architecture has.

Commandline version has int 3 debugging support, and has instructions to print flags, registers and memory. It also has an interpreter mode, which gives a user prompt before executing each instruction, and can be used to run a program step by step.

Web version gives GUI access, which shows Registers, Flags and memory as well as provide an editor to write code. It provides auto run mode, which runs program by itself, and shows which line is being executed, along with updating Flags, registers and memory as it runs. It also has support to manually run instructions one by one. Annnnnd... it comes in Dark Mode :dark_sunglasses:

As it is compiled to WASM, it does not require any back end server to run it, and complete process is done right in the browser.

# And ?
![Phineas And Ferb nanobots](https://dev-to-uploads.s3.amazonaws.com/i/169r5hp8mwajl35znqk5.gif)

So is it perfect? Nope! We are sure there might be some bugs in it, some issues that we haven't even thought of testing, and other things that we haven't thought of. And that's why its open source ! So check it out on GitHub :
* Commandline and core library is at [https://github.com/YJDoc2/8086-Emulator](https://github.com/YJDoc2/8086-Emulator)
* Web Version Repository is at [https://github.com/YJDoc2/8086-Emulator-Web/](https://github.com/YJDoc2/8086-Emulator-Web/)
* Web Version is hosted on GitHub pages at : [https://yjdoc2.github.io/8086-emulator-web/](https://yjdoc2.github.io/8086-emulator-web/)

If you think it is something cool, interesting
![Phineas And Ferb Own Star](https://dev-to-uploads.s3.amazonaws.com/i/aeagn6atn4k9oclax75h.png)
Star it on Github :smile: Also let us know in comments what do you think about it :point_down:

Thanks!

**NOTE** : All Phineas And Ferb images and GIFs are from Google image search.