Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

VirtualMachine

Guides

  • Virtual Machine Package

Symbols

  • VirtualMachineAdd
  • VirtualMachineDefinition
  • VirtualMachineExecute
  • VirtualMachineList
  • VirtualMachine
  • VirtualMachineObject
  • VirtualMachineObjectQ
  • $VirtualMachines

Other

  • Intel4004
  • MOS6502
  • NFA
  • PDP1
  • PDP8
  • RegisterMachine
"MOS6502"
​
"MOS6502" an emulator of the MOS 6502 computer architecture.
​
▪
Creating a virtual machine instance:
VirtualMachine
["MOS6502"]
create a new instance of the MOS 6502 virtual machine
▪
For the
"MOS6502"
virtual machine, the following properties can be queried:
obj["CycleCount"]
the number of cycles the machine has been run
obj["MemoryState"]
an
SparseArray
representing the state of the memory
obj["MemoryView"]
a
MenuView
representing the memory pages
obj["ProcessorState"]
an
Association
representing the state of the processor
obj["StepCount"]
the number of steps the machine has been run
▪
For the
"MOS6502"
virtual machine, the following commands can be executed using
VirtualMachineExecute
:
VirtualMachineExecute
[obj,"Debugger"]
return an interactive debugger
VirtualMachineExecute
[obj,"MemoryLoad",bin]
load a list of integers
bin
into memory
VirtualMachineExecute
[obj,"MemoryRead",addr]
read the contents of the memory address
addr
VirtualMachineExecute
[obj,"MemoryWrite",addr,val]
write
val
into the contents of the memory address
addr
VirtualMachineExecute
[obj,"ProcessorReset",org]
reset the state of the processor, setting the program counter to
org
VirtualMachineExecute
[obj,"Reset",bin,org]
reset the machine, loads
bin
into memory, and sets the program counter to
org
VirtualMachineExecute
[obj,"Run",n]
run
n
steps of the machine
VirtualMachineExecute
[obj,"RunTrace",n]
run
n
steps of the machine and return a trace of the evaluation
Examples
MoreExamples⊳
Create a new instance of the
"MOS6502"
virtual machine:
In[1]:=
mos6502=
VirtualMachine
["MOS6502"]
Out[1]=
VirtualMachineObject
Machine: MOS6502
StepCount: 0
InstructionRegister: BRK
(IMP)
ProgramCounter: 0000

Get information about the object:
In[2]:=
Information[mos6502]
Out[2]=
VirtualMachineObject
Machine Name
MOS6502
Properties
{CycleCount,Machine,MemoryState,MemoryView,ProcessorState,StepCount}
Commands
{Debugger,MemoryLoad,MemoryRead,MemoryReset,MemoryWrite,ProcessorReset,Reset,Run,RunTrace}
Functions
{Information,Normal}
Obtain the state of the processor:
In[3]:=
mos6502["ProcessorState"]//Dataset
Out[3]=
InstructionRegister
0
ProgramCounter
0
Accumulator
0
X
0
Y
0
ProcessorStatus
48
StackPointer
255
Load a program that adds the numbers 16^^C0 and 16^^C4 and stores the result in the accumulator:
In[4]:=
VirtualMachineExecute
[mos6502,"MemoryLoad",{16^^A9,16^^C0,16^^AA,16^^E8,16^^69,16^^C4},16^^600]
Out[4]=
VirtualMachineObject
Machine: MOS6502
StepCount: 0
InstructionRegister: BRK
(IMP)
ProgramCounter: 0000

Set the program counter to the start of the program:
In[5]:=
VirtualMachineExecute
[mos6502,"ProcessorReset",16^^600]
Out[5]=
VirtualMachineObject
Machine: MOS6502
StepCount: 4
InstructionRegister: BRK
(IMP)
ProgramCounter: 0600

Run the machine for 4 steps and get a trace of the execution:
In[6]:=
VirtualMachineExecute
[mos6502,"RunTrace",4]
Out[6]=
Step
Cycle
Processor
Stack
IR
PC
A
X
Y
S
P
4
8
BRK
(IMP)
0600
00
00
00
ff
N
V
u
B
D
I
Z
C
00
5
10
LDA
(IMM)
0602
c0
00
00
ff
N
V
u
B
D
I
Z
C
00
6
12
TAX
(IMP)
0603
c0
c0
00
ff
N
V
u
B
D
I
Z
C
00
7
14
INX
(IMP)
0604
c0
c1
00
ff
N
V
u
B
D
I
Z
C
00
8
16
ADC
(IMM)
0606
84
c1
00
ff
N
V
u
B
D
I
Z
C
00
Verify the program has correctly added the two numbers:
In[7]:=
BaseForm[mos6502["ProcessorState"]["Accumulator"],16]
Out[7]//BaseForm=
84
16
""

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com