CPU Sim is a software development environment for the simulation of simple computers. It was developed by Dale Skrien to help students understand computer architectures. With this application
Application software
Application software, also known as an application or an "app", is computer software designed to help the user to perform specific tasks. Examples include enterprise software, accounting software, office suites, graphics software and media players. Many application programs deal principally with...
the user is able to simulate new or existing simple CPUs. Users can create new virtual CPUs with custom machine language instructions, which are implemented by a sequence of micro instructions. CPU Sim allows the user to edit and run assembly language programs for the CPU being simulated.
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
package. This means it's platform independent (runs on every platform that has a Java virtual machine
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
installed).
Wombat 1 Sample CPU
A sample computer system, the Wombat 1, is provided with CPU Sim. It has the following registers:
The program counter , commonly called the instruction pointer in Intel x86 microprocessors, and sometimes called the instruction address register, or just part of the instruction sequencer in some computers, is a processor register that indicates where the computer is in its instruction sequence...
In a computer's central processing unit , an accumulator is a register in which intermediate arithmetic and logic results are stored. Without a register like an accumulator, it would be necessary to write the result of each calculation to main memory, perhaps only to be read right back again for...
In computing, an instruction register is the part of a CPU's control unit that stores the instruction currently being executed or decoded. In simple processors each instruction to be executed is loaded into the instruction register which holds it while it is decoded, prepared and ultimately...
The Memory Address Register is a CPU register that either stores the memory address from which data will be fetched to the CPU or the address to which data will be sent and stored....
The Memory Data Register is the register of a computer's control unit that contains the data to be stored in the computer storage , or the data after a fetch from the computer storage...
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
of the Wombat 1 computer consists of 12 instructions. Each instruction is stored on 16 bit's, the first 4 are the Opcode
Opcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...
and the other 12 are the address field.
Mnemonic
Operation code
Field length
Meaning
stop
0
16
stops the program execution
load
1
4 12
transfers data from memory to the accumulator
store
2
4 12
transfers data from the accumulator to the memory
read
3
4 (12)
puts the data from the IO console to the accumulator
write
4
4 (12)
sends to the IO console the data from the accumulator
add
5
4 12
add the data from memory to the accumulator and the result is then stored in the accumulator
subtract
6
4 12
subtracts the data from memory from the accumulator and the result is then stored in the accumulator
multiply
7
4 12
multiplies the data from the memory by the accumulator and the result is then stored in the accumulator
divide
8
4 12
divides the data from the memory into the accumulator and the result is then stored in the accumulator
jmpz
9
4 12
jump to address if the accumulator is 0
jmpn
A
4 12
jump to address if the accumulator is negative
jmp
B
4 12
unconditioned jump to address
Features
CPU Sim has the following features:
allows the creation of a CPU (a virtual one), including the registers, RAM, microinstructions, and machine instructions;
allows the creation, editing, and execution of assembly language programs for the simulated CPU;
allows stepping forward and backward through the execution of assembly language programs.
Example program for the Wombat 1 CPU
This program reads in integers until a negative integer is read. It then outputs the sum of all the positive integers.
Start: read // read n -> acc
jmpn Done // jump to Done if n < 0.
add sum // add sum to the acc
store sum // store the new sum
jump Start // go back & read in next number
Done: load sum // load the final sum
write // write the final sum
stop // stop
sum: .data 2 0 // 2-byte location where sum is stored
The following modification of the program is also used sometimes:
Start: read // read n -> acc
jmpz Done // jump to Done if n is not 0.
add sum // add sum to the acc
store sum // store the new sum
jump Start // go back & read in next number
Done: load sum // load the final sum
write // write the final sum
stop // stop
sum: .data 2 0 // 2-byte location where sum is stored
this one can use negative input to subtract, or 0 to break the loop.
Downloads
CPU Sim is a free application. You can download the latest version from the web address http://www.cs.colby.edu/djskrien/CPUSim/