CPU Sim

Jump to content
From Wikipedia, the free encyclopedia
Wombat (Animal)
Original authorDale Skrien[1]
Stable release
4.0.11 / August, 2017
Written inJava
Operating systemMS-Windows, Linux, Mac (Cross-platform)
TypeIDE
LicenseGPLv3+
Websitewww.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. With this application 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.

CPU Sim has been programmed using the Java Swing package. This means that it is platform independent (runs on every platform that has a Java virtual machine installed).

Wombat 1 Sample CPU

[edit]

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

The assembly language of the Wombat 1 computer consists of 12 instructions. Each instruction is stored on 16 bits; the first 4 are the opcode and the other 12 are the address field.

MnemonicOperation codeField lengthMeaning
stop016stops the program execution
load14 12transfers data from memory to the accumulator
store24 12transfers data from the accumulator to memory
read34 (12)puts the data from the IO console to the accumulator
write44 (12)sends the data from the accumulator to the IO console
add54 12adds the data from memory to the accumulator and the result is then stored in the accumulator
subtract64 12subtracts the data from memory from the accumulator and the result is then stored in the accumulator
multiply74 12multiplies the data from the memory by the accumulator and the result is then stored in the accumulator
divide84 12divides the data from the memory into the accumulator and the result is then stored in the accumulator
jmpz94 12jump to address if the accumulator is 0
jmpnA4 12jump to address if the accumulator is negative
jumpB4 12unconditioned jump to address

Features

[edit]

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

[edit]

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

[edit]

References

[edit]
[edit]
    Wombat (Animal)
    Original authorDale Skrien[1]
    Stable release
    4.0.11 / August, 2017
    Written inJava
    Operating systemMS-Windows, Linux, Mac (Cross-platform)
    TypeIDE
    LicenseGPLv3+
    Websitewww.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. With this application 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.

    CPU Sim has been programmed using the Java Swing package. This means that it is platform independent (runs on every platform that has a 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:

    The assembly language of the Wombat 1 computer consists of 12 instructions. Each instruction is stored on 16 bits; the first 4 are the opcode and the other 12 are the address field.

    MnemonicOperation codeField lengthMeaning
    stop016stops the program execution
    load14 12transfers data from memory to the accumulator
    store24 12transfers data from the accumulator to memory
    read34 (12)puts the data from the IO console to the accumulator
    write44 (12)sends the data from the accumulator to the IO console
    add54 12adds the data from memory to the accumulator and the result is then stored in the accumulator
    subtract64 12subtracts the data from memory from the accumulator and the result is then stored in the accumulator
    multiply74 12multiplies the data from the memory by the accumulator and the result is then stored in the accumulator
    divide84 12divides the data from the memory into the accumulator and the result is then stored in the accumulator
    jmpz94 12jump to address if the accumulator is 0
    jmpnA4 12jump to address if the accumulator is negative
    jumpB4 12unconditioned 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

    References

    1. ^ CPU SIM: A Computer Simulator for Use in an Introductory Computer Organization-Architecture Class., Authors:Skrien, Dale
    • Official website
    • GitHub Source Repository
    • CPUSim Youtube Playlist
    • CPUsimulator Applet
    Retrieved from "https://en.wikipedia.org/w/index.php?title=CPU_Sim&oldid=1195425125"