Skip to content

WArBp-3R/kit-mima-sim

Repository files navigation

kit-mima-sim

Created by Walter Alexander Böttcher (23.11.2018) Last edit: (25.11.2018)

Simulates the KIT minimal machine

You can find the example (example program from GBI sheet Nr.10 on processors (WS18/19)) on how to use the MIMA-Simulator by editing main source code in Main.java (look further down):

Dowloading/using for the first time

Download the repository in a ZIP-file (or however you want)

In the folder, run these commands:

javac Main.java
java Main

If everything works, you should now see this output:

sum: 165

Now you will only need to change the Main.java file for your own tests, then compile javac Main.java and run java Main it.

Important notes

  • Per default the KIT MIMA simulator has a valueBitSize of 24 and an adressBitSize of 20
  • Your process should end with a HALT command somehow, or the simulator will crash.
  • Loading constants below 0 or above 2^(adressBitSize)-1 may result in undesired behavior

MIMA command set

LDC const:
    loads a constant value into the accumulator
LDV adress:
    loads a value from memory at given adress into the accumulator
STV adress:
    stores the value from the accumulator in memory at given adress
LDIV adress:
    loads a value from memory at given adress,
    then uses this value as adress to load from memory into the accumulator
STIV adress:
    loads a value from memory at given adress,
    then uses this value as adress to store the accumulator value in memory
ADD adress:
    adds the value from memory at given adress to the accumulator
AND adress:
    performs the AND-operation bitwise on accumulator and value from memory at given adress
OR adress:
    performs the OR-operation bitwise on accumulator and value from memory at given adress
XOR adress:
    performs the XOR-operation bitwise on accumulator and value from memory at given adress
RAR:
    rotates the bits in the accumulator (e.g. 001100110011001100110011 -> 100110011001100110011001)
NOT:
    inverts the bits (0->1, 1->0) in the accumulator (effectively the negative value of the accumulator minus 1)
EQL adress:
    sets all bits to 1, if the accumulator value has same value from memory at given adress,
    otherwise sets all bits to 0
JMP adress:
    jumps to the instruction at given adress
JMN adress:
    executes JMP adress if first bit in accumulator is 1
HALT:
    halts the program

Main.java

public class Main {
    public static void main(String[] args) {
        //Example
        //pre-declared memory adresses
        int len = 0;
        int[] list = {1, 2, 3, 4, 5};
        int cnt = 6;
        int ref = 7;
        int sum = 8;

        //pre-declared instruction points
        int start = 0;
        int next = 5;
        int done = 18;

        //process code
        MIMAInstruction[] process = {
            new MIMAInstruction("LDC", 0), //start
            new MIMAInstruction("STV", sum),
            new MIMAInstruction("STV", cnt),
            new MIMAInstruction("LDC", list[0]),
            new MIMAInstruction("STV", ref),
            new MIMAInstruction("LDIV", ref), //next
            new MIMAInstruction("ADD", sum),
            new MIMAInstruction("STV", sum),
            new MIMAInstruction("LDC", 1),
            new MIMAInstruction("ADD", cnt),
            new MIMAInstruction("STV", cnt),
            new MIMAInstruction("LDC", 1),
            new MIMAInstruction("ADD", ref),
            new MIMAInstruction("STV", ref),
            new MIMAInstruction("LDV", cnt),
            new MIMAInstruction("EQL", len),
            new MIMAInstruction("JMN", done),
            new MIMAInstruction("JMP", next),
            new MIMAInstruction("HALT") //done
        };

        //init minimal machine
        MIMA mima = new MIMA(process);

        //pre-initialization of memory adresses
        mima.setMemValAt(len, 5);
        mima.setMemValAt(list[0], 11);
        mima.setMemValAt(list[1], 22);
        mima.setMemValAt(list[2], 33);
        mima.setMemValAt(list[3], 44);
        mima.setMemValAt(list[4], 55);

        //start minimal machine process
        mima.startProcess();

        //reading results from memory register
        int sumResult = mima.getMemValAt(sum);

        System.out.println("sum: " + sumResult);

        //can reset memory and instruction of MIMA
        mima.resetMemory();
        mima.resetInstructions();
    }
}

About

Simulates the KIT minimal machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages