MAVILERA 8086 Laboratory

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.

Three kinds of statement appear in the laboratory and in this page, and are kept apart: what Intel documents (Intel), what reverse engineering of the chip reports (RE, from Ken Shirriff's articles), and what the simulator adds for teaching (added by the simulator). Timing is labelled with the model it comes from.

Getting started

  1. Type a program in the editor, or open one from Templates: short programs that each show one idea, with a note at the top on what to try.
  2. Press Assemble (Ctrl+Enter). Errors are marked in the editor and explained in the console.
  3. Step with Step (F10) and Step back (Shift+F10), or run with Run (F5). HLT stops the run.
  4. OUT 0E9H, AL writes the character in AL to the console. Port 0E9H is the simulator's console, not an 8086 feature; other ports read 0FFH and ignore writes.
  5. 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

PartWhat it shows
Editor and listingThe source, and each instruction's address (segment:offset), bytes and fields: prefixes, op code, ModR/M, displacement and data.
Registers and flagsAX, BX, CX, DX; SP, BP, SI, DI; CS, DS, ES, SS; IP and FLAGS with OF, DF, IF, TF, SF, ZF, AF, PF, CF.
MemoryThe 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 countersCalls not yet returned from, and the instructions executed by mnemonic.
ConsoleMessages, 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.

ProfileAt 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 programCS = 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.

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

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:

ModeOne clickWhat its counts mean
StepsOne 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.
ClocksOne 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.

ElementSource
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.

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):

InstructionForms
NOPall
ADD AX,imm16; MOV AX,imm16all
PUSH r16all eight registers
MOV r16,r/m16; ADD r16,r/m16; ADD r/m16,imm16register and every memory form
SHL r/m16,CLregister and every memory form
JMP short; JZ (taken and not taken); CALL nearall

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).

ControlWhat it does
NMIA rising edge: latched, and taken at the next instruction boundary even when IF = 0. Type 2; no INTA cycles.
INTR, TypeA 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.
DelayThe 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

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.

Templates and exercises

TemplateWhat it shows
Add the words of a tableA loop over a table with ADD, LOOP and the console.
Carry, overflow, sign and zeroHow additions set the flags.
Copy and compare strings with REPMOVSB, CMPSB and the repeat prefixes.
Segments and physical addressesLoading segment registers and the addresses they make (also in the second profile).
Print a number in decimalDIV and the stack.
Install interrupt handlersINT and a divide error, through the vector table.
NMI and INTR from the Interrupts panelHandlers for NMI and INTR, HLT waiting, an interrupt inside REP MOVSB.
The trap flag: single-stepA type 1 handler counting the instructions run with TF = 1.
Fetch while executing: the queue at workIn 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

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

KeysAction
Ctrl+EnterAssemble
F5Run or pause
F10 / Shift+F10Step / step back (in the BIU and EU view, one step or one clock)
F11 / Shift+F11Step over / step out
Ctrl+F10Run to the editor's line
Ctrl+FFind in the editor
Esc, then TabLeave the editor (Tab inside it indents)
↑ ↓, Enter, BIn the listing: move, show the fields, set a breakpoint
↑ ↓, WIn the registers: move, watch
Arrow keys on a dividerResize panes (Shift for larger steps; Enter restores)
Enter on a drawn elementOpen its details

How the models were checked

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

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.