The 8086 Laboratory
Assemble and run programs for the Intel 8086 in the browser, and watch each instruction inside the processor: as teaching steps, clock by clock with the instruction queue, or with clock counts calibrated to a real chip.
About the laboratory
The Intel 8086 is a 16-bit microprocessor. Its programs address 1 MiB of memory through four segment registers, and its work is split between two units that run at the same time: the bus interface unit (BIU) fetches instruction bytes ahead into a six-byte queue, and the execution unit (EU) takes them from the queue and executes them. Intel describes the processor in The 8086 Family User's Manual (order number 9800722-03, October 1979), chapters 2 and 4; this documentation cites it as "IFUM" with its page numbers.
The laboratory has two views. Instructions runs a program one instruction at a time and shows the registers, the flags, memory and the console. BIU and EU draws the two units and shows the same program inside them, in one of three Modes: the simulator's teaching steps, clocks of a teaching model of the bus and the queue, or clocks calibrated to recorded traces of a real chip.
Getting started
- Type a program in the editor, or open one from Sample projects: short programs that each show one idea, with a note at the top on what to try.
- Press Assemble (Ctrl+Enter). Errors are marked in the editor and explained in the console.
- Step with Step (F10) and Step back (Shift+F10), or run with Run (F5).
HLTstops the run. OUT 0E9H, ALwrites the character in AL to the console. Port 0E9H is the simulator's console, not an 8086 feature; other ports read0FFHand ignore writes.- Open the BIU and EU view to see the same program inside the processor.
; add the words of a table
MOV SI, OFFSET table ; SI <- the table's offset
MOV CX, 5 ; five words
XOR AX, AX
next: ADD AX, [SI] ; AX <- AX + the word at DS:SI
ADD SI, 2
LOOP next ; CX <- CX - 1; again while CX is not 0
HLT
table DW 10, 20, 30, 40, 50
The workspace
| Part | What it shows |
|---|---|
| Editor and listing | The source, and each instruction's address (segment:offset), bytes and fields: prefixes, op code, ModR/M, displacement and data. |
| Registers and flags | AX, BX, CX, DX; SP, BP, SI, DI; CS, DS, ES, SS; IP and FLAGS with OF, DF, IF, TF, SF, ZF, AF, PF, CF. |
| Memory | The 1 MiB memory by physical address; the interrupt vector table at 00000H to 003FFH. |
| Interrupts (memory pane) | The NMI button and the INTR switch: see Interrupt inputs. |
| Call stack and counters | Calls not yet returned from, and the instructions executed by mnemonic. |
| Console | Messages, and the characters written to port 0E9H. |
Segments and memory
An 8086 address is a segment and an offset; the BIU forms the 20-bit physical address as segment × 16 + offset (IFUM Fig 2-18). Code is fetched from CS:IP, the stack is at SS:SP, data are in DS unless a prefix names another segment, and the destination of a string instruction is always ES:DI (IFUM Table 2-2). An address with BP as its base uses SS by default.
| Profile | At the reset |
|---|---|
| 8086 · one segment (default) | CS = DS = ES = SS = 1000H, SP = 0FFFEH: the program, its data and its stack share one 64K segment. |
| 8086 · segments set by the program | CS = 1000H; DS, ES, SS and SP are 0, and the program loads them itself. |
In both, the program is placed at offset 0000H of segment 1000H, IP starts at its entry, FLAGS at F002H (interrupts disabled), and the interrupt vector table starts at zero. An offset wraps within its segment (a word at offset 0FFFFH takes its second byte from offset 0000H), and physical addresses wrap at 1 MiB; both as observed in the test suite (see checks).
Assembly language
The assembler takes Intel's mnemonics in the style of Intel's ASM-86.
- Instructions: the documented 8086 instructions, with
BYTE PTRorWORD PTRwhere the size of a memory operand is not clear,SHORT,NEARandFAR, segment prefixes written asES:[DI], andREP,REPE,REPNEandLOCK. Point at a mnemonic in the editor for its operands and operation. - Directives:
DB(bytes and strings),DW(words),DUP,EQU,ORG,END,OFFSET.ASSUMEis accepted and ignored;SEGMENTandENDSare not supported: use the second profile and load the segment registers withMOV. - Labels and comments: a label may end with a colon; a comment starts with a semicolon. A label
cannot be a register, mnemonic or directive name (
waitandptr, for example). - Numbers: decimal (
12), hexadecimal with H (0CH; a leading digit is needed), binary with B (1100B), or a character ('A'). - Instructions that do not run: op codes Intel does not document (aliases, undocumented and
undefined forms) stop the run with a message.
ESCdoes nothing (there is no coprocessor);WAITandLOCKhave no effect.
The scratch line above the instruction fields turns one instruction into its bytes, or bytes into their instruction, without changing the program.
Running and debugging
- Breakpoints: click a line number in the editor or an address in the listing.
- Watchpoints: tick a register's eye to stop when it is written; double-click a memory byte to stop when it is written.
- Step back undoes one step at a time, to the start of the run.
- Step over runs a
CALL,INTorINTOto its return; Step out runs to the return of the present call; Run to cursor stops at the editor's line. - The call stack follows
CALL,INT, divide errors and interrupt entries and their returns. It follows the instructions, not the stack's contents: a program that changes SP itself can make it differ. - An interrupt through a vector that is still 0000:0000 stops the run with a message, instead of jumping to address 0: store the handler's offset and segment at 4 × type first.
- A run that does not halt stops after a large number of steps and says so.
The BIU and EU view
The view draws the two units and steps the program through them. The Mode menu chooses what one click does:
| Mode | One click | What its counts mean |
|---|---|---|
| Steps | One step of the simulator's teaching model: a queue byte, a transfer, an ALU operation, a bus request, a jump. | The simulator's description of what happens inside; not Intel's microcode, and the number of steps is not the number of clocks. |
| Clocks | One clock of a teaching model of the BIU, the queue and the EU (optionally with 1 to 3 wait states). | Intel's documented queue and bus rules; the clock counts are the model's, not the 8086's. |
| Calibrated clocks (P80C86A-2) | One clock, timed as recorded on a P80C86A-2 for the instructions listed below. | Exact clock by clock for those instructions; any other instruction keeps the teaching model's timing and is marked "not calibrated". |
Instruction ▶ and ◀ Instruction run to the end of the present instruction, or back to its start. The tabs below the drawing are Steps (the present instruction's steps and what each moves), Queue, Timeline and Waveforms.
Not every 8086 instruction is microcoded: Ken Shirriff's analysis reports that a few, such as CLC,
STI and HLT, and the prefixes, are handled by logic outside the microcode. The view marks their
steps "without microcode" [RE].
The drawing and its sources
The drawing follows the partition of the 8086 into a BIU and an EU in IFUM Fig 4-3 (p. 4-4), in the simulator's own layout. Each element's tooltip names its source.
| Element | Source |
|---|---|
| BIU and EU frames; general registers; segment registers and IP; ALU; flags; EU control; ALU data bus (16 bits); Q bus (8 bits); six-byte instruction queue; bus control logic; the 8086 bus (20-bit address, 16-bit data) | Intel: IFUM Fig 4-3, Fig 2-6 and its text |
| Address adder (segment × 16 + offset) | Intel: Fig 4-3 draws it as a block; the arithmetic, Fig 2-18 |
| Temporary registers and internal communications registers (as groups) | Intel: Fig 4-3 |
| The names IND, OPR, tmpA, tmpB, tmpC, and the ALU result Σ | RE: reverse engineering, marked "RE" in the drawing |
| The instruction decoder place (op-code, ModR/M and prefix bytes go there; constants come from it) | Added by the simulator (dashed) |
| The links "an offset from another register to the adder" and "a constant from the decoder onto the bus" | Added by the simulator (dashed) |
Clocks, the queue and the timeline
In clock mode the BIU works by Intel's documented rules (IFUM p. 2-6, p. 2-50, Figs 4-5 and 4-6, Table 4-4): the queue holds six bytes; the BIU starts a code fetch when at least two bytes are free and the EU has no request; it fetches words, and one byte first after a transfer to an odd address; a fetch already on the bus finishes before the EU's request; a bus cycle is T1 to T4, with wait states (Tw) after T3; a word at an odd address takes two bus cycles; and a transfer of control empties the queue. The queue status shows F (first byte of an instruction), S (subsequent byte) and E (queue emptied) as in IFUM Table 4-4. The EU performs one teaching step per clock and waits when the queue is empty or the bus is busy.
- Queue tab: the six cells with the next byte at the head, the cycle in progress, and the last clocks.
- Timeline tab: the bus and the EU clock by clock, to see fetching overlap execution, the queue fill
during a long instruction such as
MUL, and empty on a jump (the template "Fetch while executing"). - Waveforms tab: chosen signals, among them the T state, ALE, M/IO, RD, WR, the bus status S2–S0 and the queue status QS1–QS0, as a timing diagram, which can be exported as a VCD file.
If a program writes over code already in the queue, the 8086 would execute the old byte; the simulator decodes from memory, as the Instructions view does, and marks the byte "stale".
Calibrated clocks
Calibrated mode times instructions by single-instruction traces recorded on an Intel P80C86A-2, a CMOS 80C86, in the SingleStepTests/8086 suite, not on an original NMOS 8086. These instructions match the recorded traces clock by clock in all 2,000 tests of each (36,000 tests):
| Instruction | Forms |
|---|---|
NOP | all |
ADD AX,imm16; MOV AX,imm16 | all |
PUSH r16 | all eight registers |
MOV r16,r/m16; ADD r16,r/m16; ADD r/m16,imm16 | register and every memory form |
SHL r/m16,CL | register and every memory form |
JMP short; JZ (taken and not taken); CALL near | all |
As a second check, the loop of IFUM Fig 4-21 runs as its timing diagram, Fig 4-22 (an NMOS 8086), shows: the same at every compared clock, 55 clocks a pass, and 64 with one wait state, as the manual states. Interrupt entries and every other instruction keep the teaching model's timing and are marked "not calibrated". Calibrated mode runs without wait states.
Interrupt inputs
The Interrupts tab of the memory pane drives the 8086's two interrupt inputs (IFUM pp. 2-22 to 2-27).
| Control | What it does |
|---|---|
| NMI | A rising edge: latched, and taken at the next instruction boundary even when IF = 0. Type 2; no INTA cycles. |
| INTR, Type | A level, not latched: while the switch is on and IF = 1, the processor acknowledges with two INTA bus cycles, reads the type and takes the interrupt. The switch stays on until you turn it off, so a handler runs again after its IRET if INTR is still on. |
| Delay | The input arrives after this many instructions; each repetition of a REP string instruction counts as one. A choice of the simulator, to place an interrupt inside a string instruction. |
The rules
- Priority (IFUM Table 2-3): the instruction's own interrupt (
INT n,INTO, a divide error), then NMI, INTR and single-step. Each one recognised is entered in turn, so the last entered runs first (IFUM Fig 2-31). - An entry pushes FLAGS, CS and IP, clears IF and TF, and loads CS:IP from the vector at 4 × type (IFUM p. 2-26). In the BIU and EU view it is a step list of its own: INTA for INTR, the vector reads, the three pushes and the jump.
- No interrupt is recognised between a prefix and its instruction, nor after
MOVorPOPto a segment register until after the next instruction (IFUM p. 2-24). AfterSTIand afterIRET, INTR waits for one more instruction: this follows the manual's text and has not been checked against hardware. - A repeated string instruction accepts NMI and INTR between two repetitions. On return it resumes at the prefix just
before the string op code, the only prefix restored (Intel application note AP-67, p. A-27):
REP ES: MOVSBresumes asES: MOVSB, one more transfer. - Single-step: with TF = 1, a type 1 interrupt follows every instruction that started with TF = 1 (IFUM p. 2-25), so
not the
POPFthat sets it. In this simulator the trap is taken at the end of a whole instruction. HLTstops the run. An NMI, or INTR with IF = 1, wakes the processor; the handler returns past theHLT.
The panel shows whether NMI is latched, whether INTR is on, what is due next and why an interrupt waits. Each input is kept with the step at which it was given: stepping back past it withdraws it, and a reload, a long run or a trace export replays it there. In the BIU and EU view an input given inside an instruction arrives at its end. The templates "NMI and INTR from the Interrupts panel" and "The trap flag: single-step" show the inputs and the trap.
Sample projects and exercises
| Template | What it shows |
|---|---|
| Add the words of a table | A loop over a table with ADD, LOOP and the console. |
| Carry, overflow, sign and zero | How additions set the flags. |
| Copy and compare strings with REP | MOVSB, CMPSB and the repeat prefixes. |
| Segments and physical addresses | Loading segment registers and the addresses they make (also in the second profile). |
| Print a number in decimal | DIV and the stack. |
| Install interrupt handlers | INT and a divide error, through the vector table. |
| NMI and INTR from the Interrupts panel | Handlers for NMI and INTR, HLT waiting, an interrupt inside REP MOVSB. |
| The trap flag: single-step | A type 1 handler counting the instructions run with TF = 1. |
| Fetch while executing: the queue at work | In the BIU and EU view in clock mode: the queue filling and emptying. |
Exercises (File ▸ Exercise…) give a task and a starter program, and check your program against
tests: the largest signed word of a table, counting a character with REPNE SCASB, printing a packed BCD
byte, and a subroutine that keeps the registers. The tests set memory, then check registers, flags, memory and the
console. They were written for MAVILERA; no solutions are included.
Files, sharing and exports
- Your work is kept in this browser: after a refresh or a closed tab, the program, its file name, the cursor, breakpoints, watchpoints and the step you had reached come back.
- File ▸ Copy share link puts the program, the view and its settings into a link. They travel in the part after #, which the browser never sends to a server.
- File ▸ Save program and settings… writes a .json file; File ▸ Open reads it back, and .asm files.
- Exports: the code segment as a memory image (.hex, one byte per line, and .bin), the listing, traces (JSON lines and CSV, with the interrupt inputs replayed and each entry marked), and from the BIU and EU view a VCD waveform. File ▸ Import .hex/.bin… loads an image at offset 0000H of the code segment.
Offline use and privacy
Every computation runs in your browser. MAVILERA has no account, sends no telemetry and uploads nothing. After a first visit the hosted version also opens without a network connection, and a single-file version can be downloaded for computers that have none.
Keyboard reference
| Keys | Action |
|---|---|
| Ctrl+Enter | Assemble |
| F5 | Run or pause |
| F10 / Shift+F10 | Step / step back (in the BIU and EU view, one step or one clock) |
| F11 / Shift+F11 | Step over / step out |
| Ctrl+F10 | Run to the editor's line |
| Ctrl+F | Find in the editor |
| Esc, then Tab | Leave the editor (Tab inside it indents) |
| ↑ ↓, Enter, B | In the listing: move, show the fields, set a breakpoint |
| ↑ ↓, W | In the registers: move, watch |
| Arrow keys on a divider | Resize panes (Shift for larger steps; Enter restores) |
| Enter on a drawn element | Open its details |
How the models were checked
- Instructions. Every test of the SingleStepTests/8086 suite (version 1, commit e71c68d) for the documented op codes was replayed: 552,483 single-instruction tests passed and none failed; 5,517 were left out by the suite's own metadata or a documented quirk. Registers, memory and the flags are compared, except flags the suite calls undefined. The tests were recorded on a P80C86A-2, a CMOS 80C86.
- Teaching steps. For the same tests, the step lists give the same results as the instruction model, and their memory and I/O requests come in the order of the recorded bus cycles: 552,483 passed, none failed.
- Clock mode. The BIU and queue model runs the same tests to the same results, with 0 and 1 wait states.
- Calibrated clocks. 36,000 tests of the instructions listed above match the recorded traces clock by clock; the loop of IFUM Fig 4-22 matches at every compared clock (55 clocks, 64 with one wait state).
- Whole programs. 4,000 generated programs of 50 instructions and the templates were run on z8086,
an independent hardware description of the 8086 (nand2mario, simulated with Verilator). Where the two differ, each
difference traces to z8086, as the recorded traces or Intel's manual show: a segment prefix that z8086 carries into a
later instruction,
NEGof a zero byte in memory, andCMC. z8086 has no single-step trap. - Interrupt inputs. NMI, INTR and single-step are not in the test suite; they are checked by hand cases written from Intel's text, in every Mode of the BIU and EU view.
Agreement between models and tests is evidence about the models. It is not evidence of how any particular chip, or a hardware build, behaves where it was not measured.
Limits of the model
- The steps are the simulator's teaching model, not Intel's microcode; clock mode's counts are not the 8086's; calibrated counts hold for the instructions listed, as recorded on a CMOS 80C86.
- Not modelled: the 8087 coprocessor (
ESCdoes nothing),WAITandLOCK, bus hold and request/grant, the minimum- and maximum-mode pins, and the halt bus cycle. Interrupt-entry timing is the teaching model's. - The STI and IRET interrupt delays follow Intel's text and have not been checked against hardware. The single-step trap is taken after a whole REP instruction, not between repetitions.
- Self-modifying code is decoded from memory, not from the queue (marked "stale" in clock mode).
- A simulation shows what the model does; it is not evidence of how a hardware build behaves.
Licence and notices
© 2026 Sajid Muhaimin Choudhury. MAVILERA and its content (drawings, help texts, this documentation, example programs and exercises) are licensed under the Apache License, Version 2.0. The names and the logo are not licensed as trademarks.
The 8086 Family User's Manual is © Intel Corporation. MAVILERA reproduces no text or figure of it or of the cited reverse-engineering articles: its simulator, teaching steps, drawing, help and programs are its own, and its drawing follows the partition of Intel's Fig 4-3 in its own layout. The SingleStepTests/8086 suite (MIT licence) and z8086 were used for checking only; nothing of them is included. MAVILERA is not affiliated with or endorsed by Intel or the authors cited. Intel and 8086 are trademarks of Intel Corporation or its subsidiaries; the instruction mnemonics are Intel's.