Short Version
We made an Intel 8086 Emulator in Rust. The commandline version is at : 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/. It is hosted on GitHub pages at : 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 ๐
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/, 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...
I decided to make one ๐ค ๐ I am interested in compilers, (check my c-to-assembly blog series here) and this seemed like a good place to actually use my interest in compilers,the microprocessors course I took, and Rust.
Then ?
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) ๐
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 ๐ฅณ ๐
And what does it do ?
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 ๐ถ๏ธ
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 ?
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
- Web Version Repository is at https://github.com/YJDoc2/8086-Emulator-Web/
- Web Version is hosted on GitHub pages at : https://yjdoc2.github.io/8086-emulator-web/
If you think it is something cool, interesting
Star it on Github ๐ Also let us know in comments what do you think about it ๐
Thanks!
NOTE : All Phineas And Ferb images and GIFs are from Google image search.
Top comments (3)
Are there any tutorials for this? I am excited to build a 8086 emulator and came across this post. I have no previous knowledge of Rust or building compilers. Could you suggest me a roadmap?
Hey Nidhi, I cannot provide a complete roadmap, however I'd suggest that you should start with learning Rust, the website has some wonderful resources : rust-lang.org/learn
Then for compilers you can check this amazing book : craftinginterpreters.com/
However, I'd suggest doing some projects in Rust before trying building a compiler, as that can be a tricky project to start off with
Hope this helps!
Thankyou! Helps a lot!!