The source is on GitHub as ghewgill/emulino. Recently I put together an emulator for the AVR chip, which is also a small 8-bit microcontroller. Update: A few pointers from right here in SO: that's also the assembler's problem, or maybe the linker's, if you have one.
Similarly, your emulator doesn't have to worry about range, index or size overruns. the main loop) halt if it hits an illegal operation. A simple implementation would center around a huge switch statement that includes all possible instruction codes.Īs I said, your emulator shouldn't need to worry about illegal instructions, because the assembler shouldn't produce any. The operation is pretty simple: Start the program counter at 0 (or a pre-determined boot location), and start a loop which fetches instructions via that pointer, and apply to registers and memory whatever operation is associated with the instruction. I'd use an unsigned char * to emulate the program counter, and ints for most other stuff. You use variables in your program to emulate the registers. You can use an array of up to (e.g.) 64K bytes as the emulator's working memory. I would leave that step as the last one.Īs for your questions regarding the emulator itself: This would wrap a lot of GUI around the editor, assembler and emulator. It sounds like you want to build a complete IDE. It's the assembler's responsibility to do the syntax check and translation, that way the emulator has only the relatively easy job of executing pre-validated, legal code. The emulator doesn't include an editor (that's a development tool) nor an assembler (ditto). I think you're a little unclear on the scope of this project, at least as related to the title.Īn emulator executes binary code, and nothing else.
If there are some opensource projects which detail how an emulator is built ground-up, would appreciate.
Since microcontroller has limited RAM memory, how do I keep a check of the code length or rather the code which is executing in the memory to avoid and buffer overflow or other issues.
How do I emulate each instruction for 8051?įor registers, i can have the use un/signed integers based on the type and update the table.
Any pointers how to implement this, please let me know. I need to have a look up table for instructions or some other way to store available instructions and validate the syntax. The way I understand I can further break it down: More than the GUI element i am more interested to know how to emulate the microcontroller. When user starts the program, the instructions should be step by step updating the register windows. Have small window which shows the register values at run time. Text editor(can use editbox control) where the user can write assembly code However, I wanted to break it bit more on a granular level so that I can know which areas I need to focus before i actually start writing the code. I did found quite a lot of questions discussing this. This is no class project etc but a learning initiative from my side. I am comfortable programming in C/C++/C#. For learning purpose i intend to start building a 8051 microcontroller emulator.