user30969: 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.

user20245: 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.

user31668: 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 %temp% folder
Search for *.hex files 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 F1
Select the option Load HEX file and START simulation
Done - the simulation should run like expected.

I have created a short GIF and I hope you like it (lazy to show step by step)


30969: <p>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 <a href="https://arduino.stackexchange.com/questions/61/can-i-program-for-arduino-without-having-a-real-board">Can I program for Arduino without having a real board?</a> , but as far as I see, they are simulators rather than emulators and I can't use compiled binary programs in them.</p>
 20245: <p>There are <a href="https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems" rel="nofollow noreferrer">many different processors used in making many different types of Arduino boards</a>.  So there is no one way to write Arduino machine code. </p>

<p>There are emulator for simpler processors available for the asking.  But, while they work, it is not believe they claim to be totally accurate. </p>

<p>At one point in processor development history, <a href="https://en.wikipedia.org/wiki/In-circuit_emulation" rel="nofollow noreferrer">ICE machines</a> 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.</p>

<p>Currently, most processors are built with extra internal circuitry and interface to break program execution for debugging purposes.  <a href="https://en.wikipedia.org/wiki/JTAG" rel="nofollow noreferrer">JTAG</a> is one such industry standard / example.</p>

<p>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 <a href="https://en.wikipedia.org/wiki/Integrated_development_environment" rel="nofollow noreferrer">IDE</a> running on a host-computer / work-station.</p>
 31668: <p><strong>Disclaimer</strong>: I have no affiliation with Wokwi (based on <a href="https://github.com/wokwi/avr8js" rel="nofollow noreferrer">opensource AVR8js engine</a>) except that I have learnt a lot from it.</p>
<p>I just tried it on the free Wokwi Arduino simulator(my favourite Arduino simulator for learning) and it worked in a blink!</p>
<p><strong>Here is what I did to load the hex file into the Arduino simulator</strong></p>
<ol>
<li>Go to the Arduino IDE and open the basic blink example</li>
<li>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.</li>
<li>Once the modified example is compiled go to the <code>%temp%</code> folder</li>
<li>Search for <code>*.hex</code> files and find the one which is just the latest one (this is the <a href="https://forum.arduino.cc/t/arduino-ide-and-hex-files/49361" rel="nofollow noreferrer">only way</a> I found to grab the hex file needed)</li>
<li>Go to <a href="https://wokwi.com/arduino/libraries/demo/blink" rel="nofollow noreferrer">Wokwi Arduino Simulator with any Arduino example</a></li>
<li>Click on the editor tab in the left</li>
<li>Press function key <code>F1</code></li>
<li>Select the option <code>Load HEX file and START simulation</code></li>
<li>Done - the simulation should run like expected.</li>
</ol>
<p>I have created a short GIF and I hope you like it (lazy to show step by step)
<a href="https://i.stack.imgur.com/E9WLR.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E9WLR.gif" alt="enter image description here" /></a></p>
