MAVILERA SAP-2 Laboratory

MAVILERA SAP-2 Laboratory: documentation

Interactive Microprocessor Architecture Laboratory: Visualize. Execute. Understand.

About SAP-2

SAP-2 is the second of the simple-as-possible (SAP) computers, teaching designs by Albert Paul Malvino in his textbook Digital Computer Electronics (McGraw-Hill, first edition 1977; third edition with Jerald A. Brown, Glencoe/McGraw-Hill, 1993). The book presents SAP-1, SAP-2 and SAP-3 in turn as computers a student can build from digital components; its preface describes their instruction set as a subset of the Intel 8085's, and SAP-2's mnemonics, such as MVI, LDA, JNZ and CALL, are the 8085's. SAP-2 is a textbook design, not a commercial product.

SAP-2 has 64K of memory, the first 2K of it read-only, an accumulator and the registers B and C, the sign and zero flags, conditional jumps, a subroutine call and return, and four ports: a hexadecimal keyboard, a hexadecimal display and serial lines. Its instruction set is the 43 instructions of the book's tables.

Why it matters: SAP-2 adds what SAP-1 lacks to be programmed like a real microprocessor: decisions on flags, loops, subroutines and input and output. It bridges SAP-1 and the 8080/8085 family that the book goes on to teach.

The detailed description of SAP-2 is chapter 11 of the book. The book has no DOI.

Getting started

  1. Open the application. The editor holds a short example program; Templates in the toolbar offers others, each showing one idea, with a note at the top on what to try.
  2. Press Assemble (Ctrl+Enter). The listing shows each instruction's bytes with its address; errors are underlined in the editor and explained in the console.
  3. Press Step (F10) a few times. The current instruction is marked in the editor and the listing, and the registers, flags and ports change. Each OUT 03H also writes a line in the console.
  4. Press Step back (Shift+F10) to undo a step, or Run (F5) to run to HLT or to a breakpoint.
  5. Choose Bus at the top. The same program now runs one T state per step on the drawing of the computer.

The example program of a new session:

        MVI C,05H     ; C <- 5, the count
loop:   MOV A,C       ; A <- C
        OUT 03H       ; port 3 <- A: the display, and a console line
        DCR C         ; C <- C - 1; Z = 1 when it reaches 0
        JNZ loop      ; again until C is 0
        HLT           ; stop

A run starts at 0000H. Memory from 0000H to 07FFH is read-only: a store there stops the run with a message.

The workspace

The page is a workspace of panes, as in a code editor.

Drag a divider to resize panes; the sizes are kept in this browser for each view.

Assembly language

One instruction or directive per line, with an optional label (ending in :) and an optional comment (starting with ;). Mnemonics are not case-sensitive. Operands are separated by a comma, as in MVI A,05H.

FormWhat the assembler accepts
InstructionsThe 43 of SAP-2: ADD ANA ANI CALL CMA DCR HLT IN INR JM JMP JNZ JZ LDA MOV MVI NOP ORA ORI OUT RAL RAR RET STA SUB XRA XRI, with their register forms
RegistersA, B, C
IN p, OUT pInput port 1 or 2; output port 3 or 4. Other ports are refused.
DB v, …Bytes, −128 to 255
DW v, …Two-byte words, low byte first
ORG aThe address of what follows
NumbersDecimal, hexadecimal (0xFF, or 0FFH starting with a digit) or binary (0b11111111)

What each instruction does is shown when you point at it in the editor; the full description of the computer is in the book listed under About SAP-2.

Ports and keyboard

The Ports tab of the memory pane is the computer's front panel.

PortOn the panel
Input port 1The hexadecimal keyboard: press a key, or type a byte (00 to FF, 0FFH, 0xFF, 0b11111111) and press Enter, to put it on port 1 and set READY.
Input port 2READY (bit 0), set when a byte is entered and reset by ACKNOWLEDGE; the SERIAL IN switch (bit 7).
Output port 3The hexadecimal display.
Output port 4SERIAL OUT (bit 0) and ACKNOWLEDGE (bit 7): an OUT that sets ACKNOWLEDGE resets READY.

Each input is kept with the instruction it was entered before: stepping back past it withdraws it, and a reload or a long run replays it there. Reset clears the inputs.

Running and debugging

The Bus view

The drawing shows the W bus and the units on it: controller-sequencer, instruction register, program counter, MAR, memory, MDR, input ports, flags, accumulator A, ALU, TMP, B, C and output ports, with TMP2, a unit the simulator adds. Each step is one clock, one T state.

The microprogram of the Bus view is the simulator's own design. The book gives the units, the fetch states T1 to T3, the number of T states of each instruction and the flag test of a conditional jump; TMP2 and the constants FFFEH and FFFFH are the simulator's additions. An ALU instruction with B or C writes its result in T2 of the next fetch, when the bus is idle.

Exercises

File ▸ Exercise… lists practice exercises written for MAVILERA, each with a task and a starter program. Run the tests runs your program with each test's memory bytes and inputs and shows expected against actual. No solutions are included. A teacher's exercise file (JSON, with "arch": "sap-2") opens with File ▸ Open.

Files, sharing and exports

ExportContents
.hex, .binThe memory image from 0000H to the last byte: one byte per line for $readmemh, or raw bytes. Import .hex/.bin… loads one.
ListingAddresses, bytes and source lines
Trace (JSON lines, CSV)One record per instruction from reset to HLT
Golden dump (Bus view)Every write to ports 3 and 4 in order, then each RAM byte stored, in hexadecimal
Waveform, VCD (Bus view)The signals of the drawing, one clock per T state

The run exports replay the program from reset to its halt; the session you are in is not changed.

Offline use and privacy

Keyboard reference

KeysAction
Ctrl+EnterAssemble
F5Run or pause
F10 / Shift+F10Step / step back (one T state in the Bus view)
F11 / Shift+F11Step over / step out
Ctrl+F10Run to the editor's line
Ctrl+FFind in the editor
Esc, then TabLeave the editor (inside it, Tab indents)
↑ ↓, Enter, BIn the listing: move, show the fields, set or clear 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

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.

SAP-2 is described in Digital Computer Electronics by Albert Paul Malvino and Jerald A. Brown, © 1977, 1983 McGraw-Hill, Inc. and © 1983, 1993 Glencoe/McGraw-Hill. MAVILERA reproduces no text or figure of the book; its simulator, drawings, microprogram, help and programs are its own. It is not affiliated with or endorsed by the authors or the publisher. Intel is a trademark of Intel Corporation or its subsidiaries.