CPU Emulator + Assembler Documentation

Quick Start

  1. Open CPU EMULATOR from the GAMES menu.
  2. Write assembly in ASSEMBLY SOURCE.
  3. Click ASSEMBLE + LOAD (program loads at 0x0500).
  4. Use STEP for single-instruction execution or RUN for continuous execution.
  5. Use STOP to halt the run loop and RESET to reset CPU/memory state.
  6. Use TERMINAL I/O to queue keyboard input for memory-mapped reads and inspect character output.

Architecture Overview

Flags and Execution State

Memory Map (conventions used by emulator)

RangePurpose
0x0001JSR software-stack pointer byte (stack base is 0x0200).
0x00F0Terminal input status register (1 when input bytes are queued).
0x00F1Terminal input data register (read pops one queued byte).
0x00F2Terminal output register (write byte/ASCII char to append terminal output).
0x00F3Terminal output clear register (write any value to clear output).
0x0100-0x01FFInterrupt vector table; each vector entry is a 16-bit handler address.
0x0200-0x02FFInternal JSR return-address stack storage.
0x0400-0x042ASaved execution context during interrupt handling.
0x0500...Default program load/execution region.

Assembly Syntax

Sample Program

START:
  LFI R1, 0x0005
  LFI R2, 0x0003
  ADD R1, R2
  HALT

Complete Instruction Reference

Opcode Mnemonic Operands Behavior
0x00NOOP-No operation.
0x01LFIRn, immLoad 16-bit immediate into Rn.
0x02LFARn, RmLoad 16-bit word from address in Rm into Rn.
0x03LFALRn, RmLoad byte at address in Rm into low byte of Rn.
0x04LFAHRn, RmLoad byte at address in Rm into high byte of Rn.
0x05STORn, RmStore 16-bit word from Rn to address in Rm.
0x06STOLRn, RmStore low byte of Rn to address in Rm.
0x07STOHRn, RmStore high byte of Rn to address in Rm.
0x08MVRRn, RmMove Rm into Rn.
0x09SWRRn, RmSwap full 16-bit values of Rn and Rm.
0x0ASWPRnSwap high/low bytes within Rn.
0x0BNOTRnBitwise NOT on Rn; updates ZF.
0x0CANDRn, RmRn = Rn & Rm; updates ZF.
0x0DORRn, RmRn = Rn | Rm; updates ZF.
0x0EXORRn, RmRn = Rn ^ Rm; updates ZF.
0x0FNORRn, RmRn = ~(Rn | Rm); updates ZF.
0x10SHRRn, RmLogical right shift Rn by Rm & 0xF; updates ZF.
0x11SHLRn, RmLeft shift Rn by Rm & 0xF; updates ZF and CA.
0x12RORRn, RmRotate Rn right by Rm & 0xF.
0x13ROLRn, RmRotate Rn left by Rm & 0xF.
0x14ADDRn, RmRn = Rn + Rm; updates CA, OV, ZF.
0x15SUBRn, RmRn = Rn - Rm; updates CA, OV, ZF.
0x16MULRn, RmMultiply; low 16 bits in Rn, sets CA/OV if wide result overflows.
0x17DEVRn, RmDivide: quotient to Rn, remainder to Rm; divide-by-zero triggers interrupt 0x00.
0x18EVERn, RmSet CF if equal.
0x19EVGTRn, RmSet CF if Rn > Rm.
0x1AEVLTRn, RmSet CF if Rn < Rm.
0x1BEVGTERn, RmSet CF if Rn >= Rm.
0x1CEVLTERn, RmSet CF if Rn <= Rm.
0x1DEVNOT-Invert CF.
0x1EEVST-Set CF = 1.
0x1FEVSF-Set CF = 0.
0x20EVOF-Copy OV into CF.
0x21EVZF-Copy ZF into CF.
0x22EVCA-Copy CA into CF.
0x23JMPRnAbsolute jump to address in Rn.
0x24JMPCRnJump to Rn if CF=1.
0x25JRARnRelative jump ahead by Rn from current instruction address.
0x26JRSRnRelative jump back by Rn from current instruction address.
0x27JRACRnConditional relative jump ahead by Rn if CF=1.
0x28JRSCRnConditional relative jump back by Rn if CF=1.
0x29JRIAimmRelative jump ahead by immediate.
0x2AJRISimmRelative jump back by immediate.
0x2BJRIACimmConditional relative jump ahead by immediate if CF=1.
0x2CJRISCimmConditional relative jump back by immediate if CF=1.
0x2DJTSRRnCall subroutine at Rn; pushes return address.
0x2EJTSRCRnConditional call if CF=1.
0x2FRFSR-Return from subroutine (pop return address).
0x30RFSRC-Conditional return if CF=1.
0x31HALT-Stop execution.
0x32INTRnTrigger interrupt with low byte of Rn as ID.
0x33INTIimmTrigger interrupt with immediate low byte as ID.
0x34RFI-Return from interrupt by restoring saved context.
0x35SBI-Set interrupt block (BIF=1).
0x36CBI-Clear interrupt block (BIF=0).
0x37SPF-Enable privileged memory access (PF=1).
0x38CPF-Disable privileged memory access (PF=0).
0x39SLMBRnSet local memory begin from Rn.
0x3ASLMERnSet local memory end from Rn.