# Using the editor

[Courses](https://asm-editor.specy.app/learn/courses.md) › [Assembly basics](https://asm-editor.specy.app/learn/courses/assembly-basics.md) › Introduction

Web page: https://asm-editor.specy.app/learn/courses/assembly-basics/introduction/using-the-editor

> Build, Run, Step, Undo and Stop, a breakpoint, and where the memory, call stack and testcases are. Everything you need to run the programs in the rest of this course.

Every program in these courses sits in a small editor you can build and run on the page itself, and
its buttons are the ones the full editor has. This one adds 1, 2, 3 and 4 to a register. Press
**Build**, then press **Step** five times and watch `d0` on the right.

```m68k
    move.l #1, d0       ; x = 1
    add.l #2, d0        ; x = x + 2
    add.l #3, d0        ; x = x + 3
    add.l #4, d0        ; x = x + 4
    move.l d0, d1       ; y = x
```

## The buttons

Before you build there is one button, **Build**, next to **Open in editor** on this particular
playground.

**Build** hands what you wrote to the assembler and points the simulator at the first instruction. A
line the assembler does not understand is underlined in the code and Build stays disabled until you
fix it. Nothing has run yet: `d0` is still `00000000` and PC, the program counter above the
registers, holds `00001000`, the address of the first instruction.

Once it has built, four buttons take Build's place:

- **Step** runs one instruction and pauses. Press it once: `d0` changes from `00000000` to `00000001`, and PC advances from `00001000` to `00001002`. This instruction occupies two bytes. A 68000 instruction can occupy two to ten bytes; all five in this example occupy two.
- **Run** runs the program to the end, or to the next breakpoint. While a program is running that same button says **Pause**. Pausing makes Run, Step and Undo available, just as at a breakpoint.
- **Undo** takes the last instruction back, one press per instruction. The editor keeps the last 100 steps, which is a setting you can raise.
- **Stop** throws the run away: the registers go back to zero and the only button left is **Build** again.

The code is read only from **Build** until the program ends, so **Stop** is also how you get back to
typing.

This example has no stop instruction. It ends when execution reaches memory the program has not
written. If data followed the code, the CPU would try to execute those bytes too. Programs can end
explicitly to prevent that. The simulator also stops a run after two million instructions, a limit
you can change in Settings.

## Watching a register

Step through the five instructions with an eye on the registers panel. A register that just changed
is highlighted and shows what it held before, so `d0` climbs `00000001`, `00000003`, `00000006`,
`0000000A`, and the last instruction copies that into `d1`.

The values are written in hexadecimal, in two groups of four digits, because the size selector in the
panel's header is on **W**, for word, which is two bytes. Press **L**, for long, and each register
becomes one group of eight digits, the whole 32 bits of it. Hovering a value shows it in decimal, and
its signed value as well when the two differ. Clicking a register's name sends the memory panel to
the address that register holds.

## A breakpoint

Press **Stop**, then click in the narrow margin to the left of the code, on the line
`add.l #4, d0`. A dot appears there, which is a **breakpoint**. Press **Build** and then **Run**.

The program stops _before_ running that line, with `d0` at `00000006` and PC at `00001006`, and
**Run** carries on from there. Click the dot again to take it away. A breakpoint is what you use
instead of pressing Step fifty times to reach the one instruction you want to look at.

## Undo

With the program stopped at the breakpoint, press **Undo**. It goes backwards one instruction, `d0`
returns to `00000003` and PC to `00001004`. The simulator recorded what every instruction changed, so
it can put each one back, and that is the quickest way to look again at something that went past
while you were reading the other panel.

This lecture is written in M68K because that is where Undo works. On MIPS and RISC-V the button is
there but stepping backwards is not usable yet.

## The full editor

**Open in editor** opens this same program in a project of its own, in a new tab. It is laid out
like the editors programmers use every day: a column of icons down the left opens panels beside
it, the code sits in the middle with each open file as a tab above it, and what the program prints
appears under the code. **Build** floats at the bottom left of the code, and once the program is
built it becomes **Stop**, with **Run**, **Undo** and **Step** beside it. Building also opens a
column on the right:

- **Registers** and **Memory**, side by side. Memory shows one page of bytes at a time. Type an address in its box or use the arrows to page through, drag across a few bytes to see the number they make (signed as well as unsigned), and press the text button to read them as characters instead of hexadecimal. The byte the stack pointer is on is marked.
- **Stack pointer**, a second memory view that follows `sp` instead of a fixed address.
- **History**: what each of the last instructions changed, register by register and byte by byte, and a click sends the program back to that point.
- **Call stack**: the subroutines the program is inside right now and the address each one returns to. It stays empty until the Subroutines lecture.

The last three open from the buttons along the top of the page, as windows you can drag anywhere;
**Settings**, the gear at the bottom of the icons, can put them in the right-hand column instead.

Under the code, **Terminal** shows what the program writes, **Log** keeps a line for every build,
test run and program exit, and **Problems** lists what the assembler found wrong, each one a click
away from its line. **Testcases**, among the icons on the left, holds the starting registers,
memory and input, and the registers, memory and output you expect at the end. The **Test** button
at the bottom right of the code runs the program against all of them and says in the Log which
passed.

Try putting the breakpoint on `move.l d0, d1` instead and running from the top. `d0` reaches
`0000000A` and `d1` is still `00000000`, because the line that copies it has not run yet.

## Instructions in this Lecture

- M68K: [`move`](https://asm-editor.specy.app/documentation/m68k/instruction/move.md), [`add`](https://asm-editor.specy.app/documentation/m68k/instruction/add.md)

Previous: [Introduction](https://asm-editor.specy.app/learn/courses/assembly-basics/introduction/introduction.md)

Next: [Registers](https://asm-editor.specy.app/learn/courses/assembly-basics/introduction/registers.md)
