I play with Arduino Micro. I write my programs in directly in machine code, in binary editors (yes, I know that there are more easy ways to program an Arduino, I do it for fun and learning). Often my programs work, but if not, then I would like to run them on an emulator to understand what's exactly going on under the hood. Is there any Arduino emulator that accepts hex files with compiled program and can execute it? I already looked at tools mentioned at Can I program for Arduino without having a real board? , but as far as I see, they are simulators rather than emulators and I can't use compiled binary programs in them.
Disclaimer: I have no affiliation with Wokwi (based on opensource AVR8js engine) except that I have learnt a lot from it.
I just tried it on the free Wokwi Arduino simulator(my favourite Arduino simulator for learning) and it worked in a blink!
Here is what I did to load the hex file into the Arduino simulator
- Go to the Arduino IDE and open the basic blink example
- Change the ON time delay to 100ms (to make sure, the hex file is really loaded into the Arduino simulator and to verify it's working.
- Once the modified example is compiled go to the
- Search for
*.hexfiles and find the one which is just the latest one (this is the only way I found to grab the hex file needed)
- Go to Wokwi Arduino Simulator with any Arduino example
- Click on the editor tab in the left
- Press function key
- Select the option
Load HEX file and START simulation
- Done - the simulation should run like expected.
There are many different processors used in making many different types of Arduino boards. So there is no one way to write Arduino machine code.
There are emulator for simpler processors available for the asking. But, while they work, it is not believe they claim to be totally accurate.
At one point in processor development history, ICE machines were widely used. This is where a real processor is modified to allow access to internal controls and registers. (This actually sounds like the answer to your question.) However, as processors grew in speed and complexity, this approach grew out of favor.
Currently, most processors are built with extra internal circuitry and interface to break program execution for debugging purposes. JTAG is one such industry standard / example.
So, while the question has merit, the common practice is likely not to run code on an emulator, but to run it on the processor using the JTAG interface and an IDE running on a host-computer / work-station.