# Debugging and simulation

> Running a program on the simulated processor, stepping, breakpoints and conditions, watchpoints, registers and memory, peripherals, the serial terminal, the logic analyzer, the live circuit and looking back in it, the AI assistant (coming later) and uploading to a board (beta).

Source: https://embedarium.com/guide/debugging · Last updated: 2026-10-30


Embedarium runs your program on a simulated processor instruction by instruction and counts how many machine cycles each instruction takes. You see what the code does, what changes in the registers and memory, and how long it all takes. The simulation runs in your browser.

## Running a program {#running}

- **Run** ([[F5]]): builds first if needed, loads the program and runs it. The LEDs in the circuit, the serial terminal and the other panels update live.
- **Debug:** loads a successful build and **stops at the first instruction**, so you can follow it step by step. The button becomes available after you build the project.

Once the program is loaded, the run buttons appear on the toolbar:

| Button | Shortcut | What it does |
| --- | --- | --- |
| Breakpoint | [[F9]] | Sets or removes a breakpoint on the cursor line |
| Step | [[F10]] | Advances one instruction, stepping over a subroutine call |
| — | [[F11]] | Advances one instruction, stepping into the subroutine |
| To Cursor | — | Runs up to the cursor line |
| Run | [[F5]] | Continues to the next breakpoint |
| Pause | — | Stops the running program where it is |
| Reset | — | Resets the processor; the program starts from the beginning |
| Stop | [[Shift+F5]] | Ends debugging |

## The debugging view {#debugging-view}

![A paused program: toolbar, registers, disassembly, tabs, stop points and status bar](https://embedarium.com/assets/images/guide/en/db-paused.webp "A paused program: ① run buttons, ② registers, ③ memory and disassembly, ④ debugger tabs, ⑤ stop points, ⑥ status bar.")

In the editor, the line of the next instruction is highlighted with a **▸** marker on its left. Next to each line you see how many machine cycles (MC), clock cycles (CLK) and microseconds the line took the last time it ran; turn this on and off with the **MC/CLK** button at the top right.

1. **Run buttons:** the buttons in the table above.
2. **Registers:** the program counter (PC), the accumulator and other registers, the status flags and the active register bank. Values that changed in the last step are highlighted. The display button in the header (for example **Hexadecimal**) changes the number format.
3. **Memory and disassembly:** from the menu on the left, choose the disassembly, program and data memory or the special function registers (SFRs); hold [[Ctrl]] and click to open several sections together. While the program is paused you can change RAM, SFR and (if the target has it) EEPROM values.
4. **Debugger tabs:** **Memory**, **Peripherals**, **Serial**, **Analyzer**, **Stack**, **MCU** and **Diff** (details below).
5. **Stop points:** breakpoints by address, variable watches and watchpoints (below).
6. **Status bar:** the duration of the last step and of the whole run (machine cycles, clock cycles, seconds).

## Breakpoints {#breakpoints}

A breakpoint stops the program when it reaches that line. There are three ways to set one:

- put the cursor on the line and select **Breakpoint** or press [[F9]];
- click a line in the disassembly list;
- type the address (hexadecimal) in the **Breakpoint** field of the stop points panel and select **Add**.

A line with a breakpoint has a red dot on its left. **Run** ([[F5]]) continues until the program reaches a breakpoint.

### Conditional breakpoints {#conditional-breakpoint}

**Right-click** a line in the disassembly list ([[Shift+F10]] on the keyboard). The **Breakpoint condition** strip opens under the list:

- **Condition expression:** a single comparison of the form `<left> <comparison> <right>`. Examples: `A == 5`, `[30H] != 0`, `R3 >= 10H`. Either side can be a register (A, B, R0–R7, SP, PC, DPTR, PSW), a flag (CY, AC, OV, P), an SFR name, internal RAM as `[30H]`, external RAM as `X[100H]`, or a number. A name the selected processor doesn't have (or a C variable) is refused with the reason when you select **Apply**; write a hexadecimal number that starts with a letter with a leading 0 (`0FH`, not `FH`).
- **Break on which match:** if you type 3, for example, the program stops the third time the condition holds.

Leave both empty for an unconditional breakpoint. Save with **Apply**.

![The breakpoint condition strip](https://embedarium.com/assets/images/guide/en/db-breakpoint-condition.webp "Adding a condition to the right-clicked line in the disassembly: stop when A == 0F7H.")

### Variable watches and watchpoints {#watch}

- **Watch · Variables:** in C projects, after a build, choose global variables by name and watch them. With **Break on change** ticked, the program stops when the variable changes. A function's local variables are chosen as `function.name`, and their value is read only while the program is inside that function.
- **Watchpoint:** stops the program when a memory address (for example a cell in internal RAM) is read, written or changed. Choose the memory type and address, then select **Add**.

## Watching the peripherals {#peripherals}

The **Peripherals** tab shows the processor's peripherals live: every bit of the ports, each timer's mode and count, the UART registers and baud rate, and the state of the interrupt controller. Choose which cards appear from the list on the left.

![The Peripherals tab](https://embedarium.com/assets/images/guide/en/db-peripherals.webp "Peripherals: ports, timers, UART and interrupts, with every register's bits shown separately.")

The units shown depend on the target processor — for example PWM and ADC on the MS51, the dual DAC on the ADuC841, TWI (I²C) on the ATmega328P, and the MSSP and comparators on the PIC16F877A.

## The serial terminal {#serial-terminal}

When your program writes to the serial port (UART), the text appears on the **Serial** tab. Type in the field at the bottom and select **Send** to send text to the program; choose the line ending (for example CRLF) from the list next to it.

- **Hex:** shows incoming bytes in hexadecimal instead of text.
- **Echo:** also shows the line you sent (turn it off if the program echoes it itself).
- **Clear:** clears the screen only.

![The serial terminal](https://embedarium.com/assets/images/guide/en/db-serial.webp "The Write to serial template running: the program sends 'Merhaba Embedarium' on every line.")

## The logic analyzer {#logic-analyzer}

The **Analyzer** tab draws the level of the pins you choose over time:

1. Pick a pin from the **Add pin** list and select **Add**. Only the pins you choose are recorded.
2. Run the program; the waveforms appear.
3. Zoom the time axis in and out with the magnifier buttons.

Under each pin you see its number of **edges**, its **frequency** and its **duty cycle**. **Export** downloads the recording as VCD (for waveform viewers) or CSV; if your plan doesn't include it, the button is shown locked.

![The logic analyzer](https://embedarium.com/assets/images/guide/en/db-analyzer.webp "Pins P1.0–P1.3 while the LED pattern runs: each pin goes low in turn.")

## MCU, call stack and comparison {#other-tabs}

- **MCU:** the selected processor's pinout; each pin's function and alternate functions; key facts such as the core, memories and peripherals, and a link to the manufacturer's datasheet.
- **Stack:** the call stack — which subroutines and interrupts are nested. A wrong return instruction (for example returning from an interrupt with `RET`) shows up here as a warning.
- **Diff:** select **Capture snapshot** to record the current register, SFR and RAM state; after you advance the program, the tab lists what has changed since then.

![The processor and its pins](https://embedarium.com/assets/images/guide/en/db-pins.webp "The MCU tab: the pinout and the pin functions.")

## Code and circuit together {#with-circuit}

If the project has a circuit, the circuit is live while the program runs: LEDs light, displays and LCDs show text, and you give the program input by clicking input parts such as buttons.

- The **Simulation** view shows the code and the live circuit side by side; the line being executed is marked in the code.
- The **Circuit** view opens the whole schematic; you edit the circuit here.

![The Simulation view: code and live circuit side by side](https://embedarium.com/assets/images/guide/en/db-simulation-view.webp "The Simulation view: the running code on the left, the live circuit on the right. A lit LED shows red.")

**Fast switching (PWM).** A part that the program switches on and off faster than the eye can follow — a PWM output, for example — is drawn by how long it is on: an LED glows dimmer, a DC motor turns more slowly and a buzzer stays on instead of flickering. A part that switches slowly, like a blinking LED, is drawn on and off as it switches.

**Looking back.** In the **Circuit** view, while the program is paused, a **Look back** slider appears at the bottom of the circuit. Drag it to see the circuit as it was earlier: the time next to it shows how far back you are (for example *2.5 ms earlier*), and **Back to now** returns to the present. The slider covers the stretch the recording still holds; the recording follows the processor pins wired to the circuit (up to 16).

![The Circuit view](https://embedarium.com/assets/images/guide/en/db-circuit-view.webp "The Circuit view: the part palette on the left, the schematic in the middle, net labels and connections on the right.")

For drawing schematics and analyzing circuits: [Circuit design and analysis](https://embedarium.com/guide/circuit-design).

> [!note]
> The simulation works at instruction level and counts the cycles of every instruction; pins and the circuit are updated at the end of each instruction. The simulators are tested against reference tools (uCsim, simavr, QEMU, gpsim); even so, no target has been verified on real hardware yet.

## The AI assistant {#assistant}

> [!note]
> The AI assistant isn't available yet; it is planned as a later feature. The **Assistant** tab of the output panel is already there and says "AI assistance is not configured on this server."

When it arrives, the assistant will explain the latest build error and suggest a fix that you decide whether to apply, and explain what the code in the open file does. Using it will need your organization's license and setting (see [AI assistance](https://embedarium.com/guide/organization-structure#ai-assistance)) and your one-time [consent](https://embedarium.com/guide/account#ai-consent).

## Uploading a program to a real board (beta) {#upload-to-board}

On some targets you can write the built program to a real board over a USB–serial connection. This feature is in **beta**: the protocols were tested against a virtual board and independent programmers, but not yet on real boards.

| Target | Method |
| --- | --- |
| ATmega328P (Arduino Uno etc.) | Optiboot / STK500v1 bootloader, 115200 baud |
| Analog Devices ADuC841 | Serial download kernel (UART) |
| Nuvoton MS51 | UART ISP (partial) |

There is no board upload for the PIC16F877A, the Cortex-M0+ or the Generic 8051/8052. Web Serial is required, so use a Chromium-based browser such as Chrome, Edge or Opera.

1. Build the project.
2. Select **Upload to board** on the toolbar.
3. With **Serial port (Web Serial)** selected, select **Choose port and upload** and pick your board's port from the list the browser opens.

![The Upload to board dialog](https://embedarium.com/assets/images/guide/en/db-upload.webp "Upload to board: the target, protocol, file to write and the connection choice.")

The file to write and the serial connection stay in your browser; nothing is sent to the server. If you don't have the board with you, try the same flow against a simulated bootloader with **Virtual board — simulated bootloader**.
