MADELINE Processor Simulator

Modified ADEL with Integrated memory and New Encodings · 16-bit instructions · 8-bit data
Processor architecture, assembler, and simulator developed by Adelson Chua

Assembly

Write your program here
Click a line number to set a breakpoint. Editing clears breakpoints.

Machine code

Click for more details
AddrHexNative instruction

Architectural state

PC
00
R0
00
R1
00
R2
00
R3
00

MADELINE datapath

Hex data · binary controls
100%
MADELINE single-cycle datapath The PC selects the next instruction from ROM. A branch or jump can select a target relative to the current PC or a register. A separate incrementer supplies PC + 1 for the next instruction and for link writeback. JAL and JALR save this address in the register selected by OPC. The ALU and data memory share the register write bus. Matching net labels connect the circuits. PC + 1 Target Redirect PC 01 2:1 D Q PC CLK Next PC Address OR Taken AND AND AND AND EQ NE LT GT OPC WRSDEST Branch enable 2 → 4 DEC Branch decoder ¬W · (RS + (DEST = 00)) A Instruction ROM 256 words × 16 bits Word out Example contents Address Word 0x24 0x640C 0x25 0x0000 … … 0x30 0x9000 0x31 0x0B00 0xFD 0x0000 0xFE 0x0000 0xFF 0x4EFD 16 Field splitter 1 bit W 2 bits OPC 1 bit RS 2 bits DEST 2 bits SRC1 2 bits SRC2 8 bits Const DEST OPC 01 2:1 Link RF_WE DMX Register writeback D Q WE R0 8-bit CLK D Q WE R1 8-bit CLK D Q WE R2 8-bit CLK D Q WE R3 8-bit CLK R[SRC1] · operand A ALU operand X 4:1 Read port A SRC1 4:1 ALU read port B SRC2 4:1 DEST R[DEST] 0 0 1 2:1 RS A B CMP > = < Signed compare GT NE EQ LT 01 2:1 RS Const +ADD XOR NAND 3 An SRL OPC 0001 1011 4:1 ALU result DM read 01 2:1 MemOp PC + 1 01 2:1 Link Instruction fetch Instruction decode Instruction execute W RS Const[7] Memory decode W & RS & Const[7] MemOp OPC[0] Store DM_WE W Link RF write (W · ¬Store) + Link RF_WE Const[6:0] Sign extend 7 → 8 bits R[SRC1] + 8-bit sum SRC1[0] Const[6:0] Absolute address {SRC1[0], Const[6:0]} 0 1 2:1 OPC[1] Address[7:0] R[DEST] DM_WE CLK Data RAM 256 × 8 bits ADDR D WE Q DM read Combinational read WRSDEST TakenIndirect LinkRedirect Jump Jump decode W = 0, RS = 0 01 JAL 10 JR 11 JALR OR JR, JALR JAL, JALR PCR[SRC1] IndirectConst Target Base Base + signed Const 01 2:1 + 8-bit sum PC1 PC + 1 + 8-bit sum PC incrementer To next-PC mux and link writeback

Execution trace

CyclePCInstructionEffect at edge

Getting started

Getting started

MADELINE stands for Modified ADEL with Integrated memory and New Encodings. This single-cycle processor uses 16-bit instructions, an 8-bit datapath, four registers (R0–R3), and an 8-bit program counter. Instruction memory holds 256 words. Data memory provides 256 byte addresses for RAM and I/O.

  1. Choose File → Load Templates for an example, or File → New Assembly to write a program.
  2. Edit the Assembly panel. The live assembler updates Machine code and instruction ROM when the source is valid.
  3. Choose Step to execute the highlighted machine word. For a pseudoinstruction, Machine code shows the source line and each native word it emits.
  4. Choose Run for continuous execution and Pause to inspect the current state. Use File → Save Assembly to keep your source.

Click a Machine code instruction to inspect its encoding. Open Data memory in Architectural state to inspect RAM and mapped ports. Reset preserves data RAM. Assembling a program starts it with zero-filled RAM. Undo restores the previous cycle, and Reset starts execution again from address zero.

Edits are autosaved as a draft in this browser, including unfinished or empty source. The draft returns when you reload the page. Loading a demo preserves it; use File → Restore saved draft to return to it. The draft includes the selected I/O and its memory addresses; execution restarts from the beginning.

Before replacing edited source, choose Cancel, Continue without saving, or Save and continue. Saving downloads an assembly file. A browser draft is separate from that file and is available only in this browser; editing another program replaces the draft. If autosaving is unavailable, use File → Save Assembly.

Supported instruction set

MADELINE executes one 16-bit machine instruction per clock cycle. A pseudoinstruction can assemble into several machine instructions.

D, A, B, Base, and L stand for registers R0–R3. All four registers are writable. Results and addresses keep their low eight bits. The PC normally advances by one word.

SyntaxOperation

Notation and execution details

imm is a byte. Enter a decimal value from −128 to 255, a hex value such as 0xF0, or a binary value such as 0b11110000. SRL and SRLI use the low three bits of the shift count and fill from the left with zeros.

M[address] denotes the byte at a RAM or I/O address. For a register-based address, use offset(Base) with an offset from −64 to 63. For example, LD R3, 0(R1) reads the byte at R1 into R3. ST R3, -2(R1) stores R3 at address R1 − 2. For an absolute address from 0 to 255, use the address directly. If LEDs are mapped to 0xF0, ST R3, 0xF0 sends R3 to the LEDs.

BEQ, BNE, BLT, and BGT compare two registers. Their Z forms compare one register with zero. Both forms use one machine word. A false condition advances the PC by one.

A branch or JAL target can be a label or a signed 8-bit displacement from the current PC. JR and JALR use a register plus a numeric displacement that defaults to zero. Registers supply their values before the clock edge.

Interfacing I/O

Choose View → I/O configuration to attach a device to one byte address. All four registers are available for calculations. An unmapped address accesses data RAM.

At the default address, LD R1, 0xF0 samples a device. ST R2, 0xF0 sends the byte in R2 to its output pins. Mixed devices combine external input bits with their output state when read.

Choose Free play to add devices and assign each a distinct address. Two devices of the same type can have independent addresses. File → Load Templates lists examples for each attached address. When you change an address, an unedited device template follows it. Update address operands in your own programs when you move a device.

Available I/O devices
DevicePort bitsHow to use it
8-bit LED bankPort[7:0] → LED7…LED0Write a byte. Each 1 lights its corresponding LED.
8 momentary pushbuttonsPort[7:0] = B7…B0 inputs, active highHold a button with the pointer, Space, or Enter. Read its bit; releasing the button clears it.
4 switches + 4 LEDsPort[7:4] = SW3…SW0 inputs; Port[3:0] = LED3…LED0 outputsToggle switches and read the high nibble. Write the low nibble to control the LEDs.
RGB LEDPort[5:4] = red; [3:2] = green; [1:0] = blue; [7:6] unusedWrite intensity 0–3 for each color channel.
2-digit 7-segmentPort[7:4] = left digit; Port[3:0] = right digitWrite a byte to display two hexadecimal digits, 00–FF.
Raw 7-segment digitPort bits 0–6 = a…g; bit 7 = decimal pointSet individual segment bits to 1 to light them. This common-cathode digit uses a raw segment pattern.
8×8 LED matrixPort[7] = WR; [6] = pixel; [5:3] = row; [2:0] = columnSet the pixel and coordinates, then pulse WR from 0 to 1 to store one pixel in the 8×8 display.
Timer with displayPort[7] = RUN; [6] = RESET; [5:0] = prescaler PRUN increments the 32-bit count every P+1 CPU cycles. RESET has priority and clears count/phase. Pausing holds them; changing P clears the phase.
Ultrasonic distance sensorPort[7] = TRIG; [6] = READY; [5:0] = distance in cmSet the simulated distance from 0 to 63 cm (default 20). Pulse TRIG low → high to start a measurement. READY clears during measurement and rises after 2 + distance subsequent CPU cycles; then read bits 5–0.
Piezo / buzzerPort[7] = ON; [6:0] = frequency codeEnable a tone at 100 + 15 × code Hz. Clear ON to silence it. Press Step once to allow browser audio.
8-bit ADCPort[7:0] = ADC input codeMove VIN from 0 to 5 V. Read round(VIN / 5 × 255), from 0 to 255.
8-bit DACPort[7:0] = DAC output codeWrite 0–255 to set VOUT = code / 255 × 5 V.
8-channel relay boardPort[7:0] → K7…K0Set a bit to energize its relay and connect COM to NO. Clear it to connect COM to NC.
PWM outputPort[7] = enable; [6:0] = duty codeOne period lasts 127 CPU cycles; duty is code / 127 × 100%. Code 0 stays low and 127 stays high. Disabling resets phase and drives low.
Hobby servo motorPort[7] = enable; [6:0] = positionEnable to map codes 0–127 to 0–180°. Disabling holds the shaft at its last angle.
DC motor + H-bridgePort[7] = enable; [6] = direction; [5:0] = speedDirection 0 is clockwise, 1 counterclockwise. Enabled speed 0–63 advances 0–12° per CPU cycle. Disabling or speed 0 stops motion.
4-coil stepper motorPort[3:0] = D, C, B, A coils; [7:4] unusedSend 1, 3, 2, 6, 4, 12, 8, 9 for successive half-steps. Reverse the sequence to reverse motion; 0 releases the coils.
4×4 keypadPort[7:4] = row outputs; [3:0] = column inputsDrive one row high, then read the columns while a key is held. Scan each row to identify the key.
Rotary encoder + LEDsPort[7] = A; [6] = B; [5] = PUSH; [4:0] = LED outputsDrag between 15° detents. Each detent sends a complete A/B cycle on a 400 ms phase timer, independent of the CPU. Use Run at 60 cyc/s to sample changes. Hold the knob for PUSH; bits 4–0 drive the LEDs.
8-bit shift registerPort[3] = DIR (1 output, 0 input bank); [2] = latch/capture; [1] = CLK; [0] = DATAFor output, set DATA before each rising CLK edge, then pulse latch/capture low → high to update the eight outputs. For input, pulse latch/capture to sample the input bank; read its MSB on DATA before each rising CLK edge.
16 × 4-bit memoryPort[7] = R/W; [6] = EN; [5] = ADDR; [4] unused; [3:0] = payloadWith ADDR=1, pulse EN low → high to latch an address. With ADDR=0, pulse EN to write (R/W=0) or read (R/W=1). Read data drives bits 3–0 while read EN stays high.
16×2 LCDPort[7] = BL; [6] = E; [5] = RW; [4] = RS; [3:0] = dataKeep RW=0. Select command/data with RS, send the high nibble then the low nibble, and pulse E high → low for each.
SPI flash memoryPort[3] = CS, active low; [2] = CLK; [1] = MOSI output; [0] = MISO inputSelect the flash with CS low. Use mode 0, MSB first: sample MISO on rising CLK edges. Send 9F then dummy bytes for ID 7F 32 01.
I²C temperature / light sensorPort[1] = SDA, 0 pulls low / 1 releases; [0] = SCLAddress 0x48 exposes temperature, light, and ID A5. Write a register pointer, then use repeated START to read. Release SDA explicitly for reads and ACK sampling; finish with NACK and STOP.

Step and Run execute instructions and advance clocked device state. Switches, buttons, and sliders can also update their input values while the processor is paused. Undo restores the preceding processor cycle and its saved device state.

Reset restarts the processor and power-cycles every I/O device. It clears matrix pixels, LCD text, peripheral RAM, counters, PWM phase, shift-register storage, and pending transfers. SPI flash returns to FF. Motor and rotary positions return to zero, pending rotary steps are canceled, and momentary inputs are released. Peripheral assignments, switches, ADC voltage, sensor settings, ultrasonic target distance, and external shift-register input pins are preserved. Active input devices then supply their current values.

File → Load Templates includes the examples available for the current I/O configuration. Each device template uses its configured address.

Simulator controls

ControlAction
FileCreate, load, or save assembly source; choose a template.
StepExecute one processor cycle while paused.
UndoRestore the previous cycle while paused.
BreakpointsClick a source line number to pause Run before its first machine word. Click again to remove the breakpoint. Step executes one native word. Run continues through the expansion. Reset retains breakpoints. Editing or replacing the source clears them.
Run / PauseStart or pause continuous execution.
ResetReset the processor and I/O devices, clearing display data, device memory, counters, and pending transfers. Keep peripheral assignments and external input settings.
View → AppearanceChoose Light mode or Dark mode for the workbench and Assembly editor. The browser remembers your selection.
View → Simulation speedSet the continuous execution rate from 1 to 60 cycles per second.
View → Show datapathShow or hide the diagram while keeping the attached devices visible. Datapath animations are disabled while the diagram is hidden.
View → Datapath animationsToggle the flash effect on changing datapath values.

While paused, Right Arrow executes one cycle when focus is outside menus, dialogs, and form controls.

Drag a divider between the top panels to change their widths. Double-click a divider to restore the default widths.

Drag the horizontal bar below the top panels to change all three panel heights. You can also use the Assembly editor's bottom-right resize handle. Double-click the bar to restore the default height, which shows at least 13 assembly lines.

About this simulator

When I designed ADEL, I wanted students to be able to follow every little detail of how a processor works. But after writing assembly programs and getting ADEL to talk to different peripherals, I found myself asking another question. Just how much more can we make this little processor do? I thought it would be fun to give it branches that compare two registers, loads and stores to access data memory, and even function calls.

The catch? I wanted to keep the 16-bit instructions, the 8-bit datapath, and the same four general-purpose registers. Looking for unused instruction encodings became a puzzle in its own right. It even made me rethink the ALU. If I could choose only four operations, which four would earn their place? Take a left shift by one bit. With an adder already there, all I have to do is add a number to itself.

That’s where pseudoinstructions came in. I could write a familiar instruction in assembly and let the assembler turn it into a short sequence the hardware already knew how to execute. And thus, MADELINE was born. As you explore the simulator, I hope you’ll try stepping through one of those sequences yourself. Part of the fun in computer engineering is figuring out how much you can do with how little you have.

— Adel

MADELINE extends the original ADEL processor with data memory, register comparisons, and subroutine calls. Explore the MADELINE datapath.

ADEL (Architecture Design that's Easy to Learn)

Architecture conceptualized by Adelson Chua.

Development is ongoing; feedback is appreciated!

From EEEI, UP Diliman, for digital design and computer architecture students and anyone curious about what goes on inside a processor.

Feel free to explore, experiment, and learn how a processor really works!

Data memory

Read each address from its row and column. Shaded cells are mapped devices. The outline marks the current LD or ST address.

Save your assembly changes?

Your Assembly editor has unsaved file changes.

This action replaces your current assembly. Save a file before continuing.

Choose I/O configuration

Assign a byte address to a device, or choose Free play to connect several devices.

Instruction encoding

How the selected assembly instruction becomes a 16-bit MADELINE machine word.

Stepper motor reference

Four coil outputs · eight-phase half-step sequence

The example uses port 0xF0. Substitute the address shown on your device. Each output bit energizes one coil.

Coils and phases

Port bitCoilMeaning
[0]A1 energizes the coil; 0 releases it. Bits 7–4 are unused.
[1]B
[2]C
[3]D
Eight repeating coil patterns for half-step rotation The forward order is decimal 1, 3, 2, 6, 4, 12, 8, 9, then 1 again. Read the sequence backward to reverse rotation. Forward: move to the next pattern, then wrap to 1 AA+BBB+C CC+DDD+A 1326 41289 Reverse: visit the same adjacent patterns backward
The numbers are decimal coil masks. Holding a pattern holds position; each adjacent transition moves one half-step.

Move and hold

  1. Write a valid coil pattern to establish the initial phase.
  2. Write the next adjacent pattern for each forward half-step, or the previous pattern for reverse motion.
  3. Keep the current pattern to hold position. Write zero to release all coils.
LI   R3, 1   # A: establish the starting phase.
ST   R3, 0xF0
LI   R3, 3   # A+B: one forward half-step.
ST   R3, 0xF0
LI   R3, 2   # B: another forward half-step.
ST   R3, 0xF0
LI   R3, 3   # A+B: one reverse half-step.
ST   R3, 0xF0
hold:
J    hold    # Keep A+B energized and hold position.

The simulator uses 0.9° per half-step, or 400 half-steps per turn. The first pattern after release establishes a phase without movement. Skipped phases or invalid coil masks flag a sequence error and leave the position unchanged. Reset clears the error and position.

Add delay instructions between patterns to slow movement. The File → Load Templates example demonstrates a complete forward and reverse sequence.

4×4 keypad reference

Drive one row · read the active column

The example uses port 0xF0. Substitute the address shown on your device. The upper nibble drives rows; the lower nibble reads columns.

Rows, columns, and key labels

Row outputCOL0
bit 0 · 01
COL1
bit 1 · 02
COL2
bit 2 · 04
COL3
bit 3 · 08
ROW0 · bit 4 · 10123A
ROW1 · bit 5 · 20456B
ROW2 · bit 6 · 40789C
ROW3 · bit 7 · 80*0#D

Masks in the table are hexadecimal. Rows run from top to bottom; columns run from left to right. Signals are active high.

For key 5, drive 20 to select ROW1. While the key is held, COL1 reads high and the port reads 22.

Scan a key

  1. Write one row mask: 10, 20, 40, or 80.
  2. Read the low nibble with ANDI and mask 0F. A held key in the selected row sets its column bit.
  3. If the result is zero, select the next row. Combine the selected row and returned column to identify the key.
  4. After accepting a key, keep scanning its row until the columns return to zero. This counts one event per press.
# Poll key 5 in the second row; R2 records its column mask.
CLR  R2
poll:
LI   R3, 0x20  # 0x20: drive ROW1 only.
ST   R3, 0xF0
LD   R3, 0xF0
BEXTI R1, R3, 1  # Test COL1, the column of key 5.
BEQZ R1, poll    # Wait until key 5 is held.
ANDI R2, R3, 15  # Save the returned column mask (0x02).
release:
LD   R3, 0xF0
ANDI R1, R3, 15
BNEZ R1, release # Wait for release before accepting another press.
J    poll

The simulator models one held key at a time. Use File → Load Templates for a complete four-row scanner.

Rotary encoder reference

15° detents · independent A/B timing · five LED outputs

The example uses port 0xF0. Substitute the address shown on your device. Drag the outer ring between 15° detents. Hold the center knob for PUSH.

Port signals

Port bitsSignalUse
[7], [6]A, B inputsRead both together with mask C0 to identify their phase.
[5]PUSH inputMask 20 reads high while the knob is held.
[4:0]LED4…LED0 outputsWrite a five-bit value; each set bit lights its LED.

From a detent to A/B transitions

The knob snaps to 24 positions per turn. Each snap queues one complete A/B cycle; queued cycles run in order, including after mouse release.

Clockwise quadrature waveform The A and B pair follows 00, 01, 11, 10, 00 for clockwise rotation. B rises before A. Each emitted phase uses a 400 millisecond wall-clock timer, including the final idle phase. CPU speed and pausing do not control the timer. A · bit 7B · bit 6 0001111000 Idle400 ms400 ms400 ms400 ms Counterclockwise: 00 → 10 → 11 → 01 → 00
Read A/B as a pair. Masked port values in hexadecimal are 00, 40, C0, 80, 00 for clockwise motion.

Each phase uses a 400 ms wall-clock timer, including the final 00 interval. A/B continues changing while the CPU is paused. Changing simulation speed changes how often your program samples the inputs.

Capture a complete step

  1. Wait for idle 00 before accepting a new step.
  2. Read A/B together with mask C0. Keep the previous phase and direction in the program's control flow.
  3. Ignore repeated samples. Follow adjacent phases in the chosen direction, including any reversal back through previous phases.
  4. Count once when a complete valid sequence returns to 00.
  5. If a phase jump is invalid, discard the incomplete step and wait for 00 to synchronize again.

The File → Load Templates example implements this state machine and resets the five-LED count when PUSH is held.

Use Run at 60 cyc/s for the best capture. A faster simulation gives the polling loop more samples per phase. Slow execution can miss transitions; polling cannot recover a complete cycle that passed between samples. Use Step to inspect the instructions and Run to capture rotation.

Read inputs and write LEDs

LD   R3, 0xF0  # Capture A, B, and PUSH in one sample.
SRLI R1, R3, 6    # A:B as a two-bit number.
BEXTI R2, R3, 5   # PUSH as 0 or 1 from the same sample.
LI   R0, 5    # Light LED2 and LED0.
ST   R0, 0xF0

These instructions show individual port operations. The full template uses the same atomic A/B reads while validating the complete phase sequence.

16 × 4-bit memory reference

Latch an address · transfer a four-bit value

The example uses port 0xF0. Substitute the address shown on your device. Sixteen locations each store one nibble, from 0 to 15.

Control bits and shared payload

Port bitsSignalAction
[7]R/WData phase: 0 writes; 1 reads.
[6]ENA rising edge commits one address or data transfer.
[5]ADDR1 selects address capture; 0 selects data transfer.
[4]UnusedKeep this bit zero for simple commands.
[3:0]PayloadAddress 0–15 during address capture; data 0–15 during a write or read.
Address capture followed by a data transfer With ADDR high, prepare an address while EN is low and raise EN to capture it. Lower EN, select ADDR low and the read or write direction, then raise EN to transfer data at the stored address. 1. Latch addressADDR=1 · payload=addressEN: 0 → 1 2. Transfer dataADDR=0 · R/W=0 or 1EN: 0 → 1 Lower EN between transfers. The selected address stays latched for later reads or writes.
ADDR chooses how the shared payload is used. R/W controls only the data phase; address capture accepts either R/W level.

Write, then read the same location

  1. Set ADDR=1 and place the address in bits 3–0 with EN low. Raise EN to latch the address.
  2. Lower EN. Set ADDR=0, R/W=0, and the data nibble. Raise EN to write the selected location.
  3. Lower EN. Keep ADDR=0 and set R/W=1. Raise EN to load the selected cell into the read latch.
  4. While read EN stays high, read bits 3–0 with mask 0F. Lower EN before the next transfer.
# Store 9 at address 3, then read it into R2.
LI   R3, 0x23  # 0x23: ADDR=1, EN=0, address=3.
ST   R3, 0xF0
LI   R3, 0x63  # 0x63: EN rises and captures address 3.
ST   R3, 0xF0
LI   R3, 9   # 0x09: EN=0, ADDR=0, R/W=0, data=9.
ST   R3, 0xF0
LI   R3, 0x49  # 0x49: EN rises and writes 9.
ST   R3, 0xF0
LI   R3, 0x80 # 0x80: EN=0, ADDR=0, R/W=1.
ST   R3, 0xF0
LI   R3, 0xC0 # 0xC0: EN rises and captures read data.
ST   R3, 0xF0
LD   R3, 0xF0
ANDI R2, R3, 15  # R2=9; strip the control bits.
LI   R3, 0x80    # Lower EN to release readback.
ST   R3, 0xF0
done:
J    done

Holding EN high performs one transfer. The read latch drives only bits 3–0 while R/W=1, EN=1, and ADDR=0. Reset clears all sixteen cells, the selected address, and the read latch.

Shift-register GPIO reference

Eight pins · one direction for the whole bank

The example uses port 0xF0. Substitute the address shown on your device. Its four control bits operate the separate GPIO bank, P7…P0.

Control bits

Port bitSignalAction
[3]DIR1: all eight GPIO pins are outputs. 0: all are inputs and their toggles are editable.
[2]LATCH / CAPRising edge: output mode copies the shift byte to the pins; input mode captures the eight pins.
[1]CLKRising edge: shift one bit. Lower CLK before the next bit.
[0]DATAOutput mode: bit to shift in. Input mode: captured bit to read.

Output: shift first, latch once

Shift eight serial bits, then latch them onto eight GPIO outputs In output mode, DATA enters bit zero at the right. Rising clock edges move existing bits toward bit seven at the left. The example shift byte is A5, binary 10100101. A separate rising LATCH edge copies all eight bits to the GPIO pins. DIR=1: CLK↑ shifts toward bit 7 SHIFTGPIO 7 1 1 6 0 0 5 1 1 4 0 0 3 0 0 2 1 1 1 0 0 0 1 1 DATA LATCH↑ copies all eight bits A5 = 10100101; pins change only when LATCH rises
Send the most-significant bit first. Each CLK rising edge shifts left and inserts DATA into bit 0. A separate LATCH rising edge updates all eight pins together.
  1. Write port 08: DIR=1, CLK=0, LATCH=0.
  2. Send bits 7 through 0. Set DATA while CLK is low, then pulse CLK high → low for each bit.
  3. Keep CLK low and pulse LATCH high → low. The pins now show the completed byte.
# One output bit, then a separate latch pulse:
LI   R3, 9     # DIR=1, DATA=1, CLK=0
ST   R3, 0xF0
LI   R3, 11    # CLK rises: shift this bit
ST   R3, 0xF0
LI   R3, 9     # CLK falls
ST   R3, 0xF0
# Use 8,10,8 for a 0 bit; send all eight bits before latching.
LI   R3, 13    # LATCH rises: update the GPIO pins
ST   R3, 0xF0
LI   R3, 9     # Lower LATCH
ST   R3, 0xF0

Input: capture, read, then clock

  1. Write 00 to select input mode. Set the GPIO pin toggles.
  2. Write 04, then 00 to pulse CAP. This snapshots all pins and immediately exposes captured bit 7 on DATA.
  3. Read DATA before raising CLK. A CLK rising edge advances to the next captured bit. Collect eight bits, most-significant first.
  4. Pulse CAP again to read a new pin pattern. Toggle changes after capture apply to the next snapshot.
# One input bit after CAP:
LD   R3, 0xF0
ANDI R1, R3, 1   # Read the current captured bit
LI   R3, 2   # CLK rises: advance to the next bit
ST   R3, 0xF0
CLR  R3      # CLK falls; repeat for the next sample
ST   R3, 0xF0

DIR selects the whole bank. Changing direction alone does not shift or capture data. CAP/LATCH takes priority if it rises together with CLK; pulse the controls separately for clear transfers. After eight input shifts, DATA becomes zero until a new capture.

SPI flash reference

Mode 0 · MSB first · one 256-byte flash

The example uses port 0xF0. Substitute the address shown on your device. Software writes create the clock edges.

Connect the four signals

Port bitSignalMeaning
[3]CSOutput. 0 selects the flash; 1 ends the transaction.
[2]CLKOutput. Idle low; each rising edge transfers one bit.
[1]MOSIOutput. Command, address, or data sent to the flash.
[0]MISOInput. Data returned by the flash. Mask with 0x01.

Begin with CS=1, CLK=0 (port 0x08), then lower CS. Set MOSI before raising CLK. Sample MISO while CLK is high, then lower CLK. Transfer bit 7 first.

What one byte looks like

SPI mode 0: transmitting command 9F CS is low throughout eight clock pulses. CLK starts low. Rising edges sample MOSI bits 1,0,0,1,1,1,1,1, from bit seven to bit zero. MISO returns FF during the command byte. CS stays low for the following dummy bytes that clock out the ID. CS CLK MOSI MISO CS stays low for the reply 1 0 0 1 1 1 1 1 FF during the command byte ↑ sample ↑ sample bit 7 → bit 0
Command 0x9F = 10011111. Dotted lines mark the eight rising sampling edges. The flash returns FF during this command. Keep CS low while clocking the following ID bytes.

Mode 0 means CPOL=0, CPHA=0: clock low between transfers, capture on rising edges, prepare the next data bit on falling edges. See Microchip’s SPI timing reference.

# One bit with CS selected:
LI   R3, 2    # CLK=0, MOSI=1
ST   R3, 0xF0
LI   R3, 6    # CLK rises
ST   R3, 0xF0
LD   R3, 0xF0
ANDI R1, R3, 1    # Read MISO into R1
LI   R3, 2    # CLK falls
ST   R3, 0xF0

Commands implemented by this flash

First byteFollowing bytesResult
9F · IDClock dummy bytes.MISO returns 7F 32 01, repeating if clocking continues.
03 · ReadThree address bytes, high first; then dummy bytes.MISO returns consecutive flash bytes.
06 · Write enableRaise CS.Sets the write-enable latch (WEL).
04 · Write disableRaise CS.Clears WEL.
05 · StatusClock dummy bytes.Returns 02 if WEL is set, otherwise 00.
02 · ProgramThree address bytes, then data bytes; raise CS.With WEL set, commits complete data bytes and clears WEL.

During a read, dummy MOSI bytes supply clocks. Only the returned MISO bytes after the command/address are the requested data.

Read ID, with CS low for all four bytes:
MOSI:  9F  00  00  00
MISO:  FF  7F  32  01

Program one byte, then read it back

  1. Send 06 in its own CS-low transaction; raise CS to set WEL.
  2. Lower CS and send 02 00 00 10 A5. Raise CS to program address 0x10.
  3. Lower CS and send 03 00 00 10 00. The final received byte is A5 when the location began as FF.

Model limits: Flash starts at FF. A 24-bit address uses its low eight bits to select storage; sequential accesses wrap through 256 bytes. Programming applies old AND new, so it clears bits. Reset restores FF; erase commands and busy delays are not modeled. An incomplete final byte is discarded; earlier complete program bytes still commit. WEL clears only when data commits.

I²C sensor reference

Two wires · address 0x48 · temperature, light, and ID

The example uses port 0xF0. Substitute the address shown on your device. MADELINE controls the bus and the sensor responds.

Drive or release SDA

Port bitSignalMeaning
[1]SDAWrite 0 to pull the data line low. Write 1 to release it. Reads return the resolved line level.
[0]SCLClock output. 0 is low; 1 is high.

Released SDA can still read low. SDA reads 0 when the sensor pulls it low, even if software last wrote 1. Keep SDA released during sensor ACKs and incoming data.

Port value:  0 = SDA low,      SCL low
             1 = SDA low,      SCL high
             2 = SDA released, SCL low
             3 = SDA released, SCL high

Initialize the idle bus with port value 3, then write 1 to make START: SDA falls while SCL stays high. Write 0 to lower SCL before sending the first address bit.

Use explicit values 2 and 3 for ACK and read clocks, for example LI R3,3 followed by ST R3,0xF0. Copying a sampled SDA=0 back into the output can hold the line low. The simulator keeps the output request separate from the sampled input.

START, eight bits, ACK, STOP

I2C address byte 90 with a ninth-clock ACK SDA falls while SCL is high to make START. Eight rising clocks transfer 1,0,0,1,0,0,0,0. On the ninth clock the controller releases SDA and the sensor holds it low for ACK. SDA rises while SCL is high to make STOP. SCL SDA 1 1 0 2 0 3 1 4 0 5 0 6 0 7 0 8 START STOP 9 0 ACK 0x90 = address 0x48 + write bit 0 sensor drives 0
0x90 = 10010000 sends seven-bit address 0x48 with the write bit. The controller releases SDA for clock 9; the sensor pulls it low to acknowledge.
  • START: SDA falls while SCL stays high. STOP: SDA rises while SCL stays high.
  • Send eight bits, most significant first. Keep data stable while SCL is high.
  • Clock 9 is the receiver’s reply: SDA low is ACK; released/high is NACK.
  • After a sensor data byte, the master drives ACK=0 to request another byte, or releases SDA for NACK=1 to finish.

These timing terms follow NXP UM10204, sections 3.1.1–3.1.6. The sensor registers below are specific to this simulator.

Select a register, then read it

The seven-bit address is 0x48. Append a direction bit: 0x90 writes and 0x91 reads. The first byte after a write address selects the register pointer.

START → 90 → ACK → 04 → ACK
repeated START → 91 → ACK → A5 → master NACK → STOP
  1. Send START, address 90, and pointer 04. Release SDA and check the sensor’s ACK after each byte.
  2. Issue another START without a STOP. This repeated START retains the pointer. Send read address 91 and check its ACK.
  3. Release SDA for all eight read clocks. Shift the sampled bits into a byte: ID A5 = 10100101.
  4. Release SDA on the ninth clock to send NACK, then send STOP. For multiple bytes, send master ACK between bytes and NACK after the last.
# STOP after a read:
CLR  R3       # SDA low while SCL is low
ST   R3, 0xF0
LI   R3, 1    # Raise SCL, keep SDA low
ST   R3, 0xF0
LI   R3, 3    # Release SDA while SCL stays high
ST   R3, 0xF0

Read-only sensor bytes

PointerByteExample at 22.5 °C and light 420
00Temperature low byte2D
01Temperature high byte00: signed 0x002D ÷ 2 = 22.5 °C
02Light low byteA4
03Light high byte01: unsigned 0x01A4 = 420
04IdentificationA5

Read low byte first, then high byte. Interpret temperature as a signed 16-bit two’s-complement value divided by two. Light is unsigned. Change measurements with the peripheral’s controls.

Model limits: Only address 0x48 acknowledges. A write transaction accepts one pointer byte; additional data bytes receive NACK and do not alter measurements. Each completed read advances the eight-bit pointer, including the final NACK. Other pointer values return 00. This single-controller model omits clock stretching and arbitration.

16×2 LCD command & ASCII reference

Commands supported by this simulator's HD44780-style 4-bit interface.

Supported commands (RS = 0)

CommandMeaningSimulator behavior
0x01Clear displayFills both 16-character lines with spaces and returns the write address to line 1, column 1.
0x02Return homeMoves the write address to line 1, column 1 without erasing any characters already stored.
0x04Entry mode: decrementAfter each ASCII character is written, the address moves one position backward. The simulator wraps between the two visible lines.
0x06Entry mode: incrementAfter each ASCII character is written, the address advances one position. This is the normal mode for left-to-right text.
0x08Display offHides the characters without clearing display memory. A later display-on command shows the stored text again.
0x0CDisplay onShows the stored characters. Cursor and blink bits are not visually modeled.
0x80–0x8FSet line 1 address0x80 selects column 1 and 0x8F selects column 16 of the first line.
0xC0–0xCFSet line 2 addressLine 2 uses DDRAM addresses 0x40–0x4F; therefore 0xC0 selects line 2, column 1 and 0xCF selects column 16.

Printable ASCII data (RS = 1)

Send printable ASCII bytes 0x20–0x7E. The character is written at the current LCD address, then the address moves according to the selected entry mode. Each byte still uses two 4-bit transfers: high nibble first, then low nibble.

Hex0123456789ABCDEF
2xSP20!21"22#23$24%25&26'27(28)29*2A+2B,2C-2D.2E/2F
3x030131232333434535636737838939:3A;3B<3C=3D>3E?3F
4x@40A41B42C43D44E45F46G47H48I49J4AK4BL4CM4DN4EO4F
5xP50Q51R52S53T54U55V56W57X58Y59Z5A[5B\5C]5D^5E_5F
6x`60a61b62c63d64e65f66g67h68i69j6Ak6Bl6Cm6Dn6Eo6F
7xp70q71r72s73t74u75v76w77x78y79z7A{7B|7C}7D~7E—