# CPU Sim

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/CPU_Sim
> Markdown URL: https://mediated.wiki/source/CPU_Sim.md
> Source: https://en.wikipedia.org/wiki/CPU_Sim
> Source revision: 1195425125
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Software development environment

Wombat (Animal) Original author Dale Skrien[1] Stable release 4.0.11 / August, 2017 Written in Java Operating system MS-Windows, Linux, Mac (Cross-platform) Type IDE License GPLv3+ Website www.cs.colby.edu/djskrien/CPUSim/

**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](/source/Computer_architectures). With this [application](/source/Application_software) the user is able to simulate new or existing simple CPUs. Users can create new virtual CPUs with custom [machine language](/source/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.

**CPU Sim** has been programmed using the [Java](/source/Java_(software_platform)) [Swing](/source/Swing_(Java)) package. This means that it is [platform independent](/source/Platform_independent) (runs on every platform that has a [Java virtual machine](/source/Java_virtual_machine) installed).

## Wombat 1 Sample CPU

A sample computer system, the Wombat 1, is provided with **CPU Sim**. It has the following registers:

- pc ([program counter](/source/Program_counter));

- acc ([accumulator](/source/Accumulator_(computing)));

- ir ([instruction register](/source/Instruction_register));

- mar ([memory address register](/source/Memory_address_register));

- mdr ([memory data register](/source/Memory_data_register));

- status.

The [assembly language](/source/Assembly_language) of the Wombat 1 computer consists of 12 instructions. Each instruction is stored on 16 bits; the first 4 are the [opcode](/source/Opcode) 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 memory read 3 4 (12) puts the data from the IO console to the accumulator write 4 4 (12) sends the data from the accumulator to the IO console add 5 4 12 adds 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 jump 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 acc < 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 nacc is 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.

## See also

- [Electronics portal](https://en.wikipedia.org/wiki/Portal:Electronics)

- [Comparison of EDA software](/source/Comparison_of_EDA_software)

- [List of free electronics circuit simulators](/source/List_of_free_electronics_circuit_simulators)

- [Computer architecture simulator](/source/Computer_architecture_simulator)

## References

1. **[^](#cite_ref-1)** [CPU SIM: A Computer Simulator for Use in an Introductory Computer Organization-Architecture Class.](https://www.eric.ed.gov/ERICWebPortal/custom/portlets/recordDetails/detailmini.jsp?_nfpb=true&_&ERICExtSearch_SearchValue_0=EJ506897&ERICExtSearch_SearchType_0=no&accno=EJ506897), Authors:Skrien, Dale

## External links

- [Official website](http://www.cs.colby.edu/djskrien/CPUSim/)

- [GitHub Source Repository](https://github.com/Colby-CPU-Sim/CPUSim)

- [CPUSim Youtube Playlist](https://www.youtube.com/watch?v=6WY16EVo8Hk&list=PL72UAFEvHUFrYhw9CIWLtd9LNI1fsXfsk)

- [CPUsimulator Applet](http://www.science.smith.edu/~jcardell/Courses/CSC103/CPUsim/cpusim.html)

---
Adapted from the Wikipedia article [CPU Sim](https://en.wikipedia.org/wiki/CPU_Sim) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/CPU_Sim?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
