Getting Started with Mythsim

By Dale Read

Downloading

Visit MythSim.org to download the mythsim simulator. Note that you will need to have Java installed. The mythsim site has more information on this. Also take a look at the manual section at the mythsim site.

Running

Once mythsim has been installed, you will have a file called mythsim.jar. Selecting this file will launch Mythsim, the Java-based simulator. In the initial window, select the File menu to load files. To run any "program" you must have two files, a microcode file and a memory file. The default extensions for these are .ucode for the microcode file, and .mem for the memory file. Actually any text files will work. Be sure to first load the microcode file, and second load the memory file, otherwise you will get a screenful of errors. The format of these two files is described further below.

Once these files are loaded, you will want to select Plugins to watch the execution. You can watch the datapath, observe line by line as the microcode is executed, and watch line by line as the contents of main memory is retrieved and used.

What we are Attempting to Do

Mythsim allows us to invent an assembly-language of our choosing, and then implement this assembly language within our simulated CPU. Typically the assembly language we create will have elements that any assembly language would have in it, such as add, subtract, logical operations (and, or, not, xor), shift, multiply, memory read, and memory write. We could, however, come up with unique instructions, such as ADD3 ri; which would implement ri = ri + 3; (ADD3 ri is of questionble usefulness.)

By doing this we learn the nuts-and-bolts of how to control the datapath using a control unit of our own devising, which in turn should give a greater appreciation of programming language implementation and efficiency issues. This also helps us to understand how a computer actually works, "under the hood."

Note that the microprogrammed control unit could instead be equivalently rendered as a hard-wired control unit. The hard-wired control unit would be faster, however less flexible.

File Formats

As mentioned above, each "program" is made up of two text files, the microcode file and the memory file. The microprogram controlling how the CPU behaves is comes from the microcode file. The program to run, essentially an assembly language program, comes from the memory file. The microprogram implements the instruction set used in the assembly language program.

Microcode

A sample microcode file is:

// ========= FETCH =========
fetch0: a_sel=7, b_sel=7, alu_sel=AND, r6_write, mar_sel=LOAD;
fetch1: a_sel=6, c_in, alu_sel=ADDA, r7_write, ir0_sel=LOAD, read, if wait then goto fetch1 endif;
fetch2: a_sel=7, b_sel=7, alu_sel=AND, r6_write, mar_sel=LOAD;
fetch3: a_sel=6, c_in, alu_sel=ADDA, r7_write, ir1_sel=LOAD, read, if wait then goto fetch3 endif;

// ========= OPCODES =========
switch: goto opcode[IR_OPCODE];
opcode[0]: goto fetch0;                                                         // no_op
opcode[1]: ri_sel, rj_sel, rk_sel, alu_sel=ADD, goto fetch0;  // add (ri <- rj + rk)
opcode[2]: result_sel=IR_CONST8, ri_sel, goto fetch0;        // load immediate (ri <- ir_const8)
opcode[3]: goto opcode[3];                                                   // halt


Notes:

Memory

A sample memory file corresponding to the above microprogram file is:

Top section of program before the % can be used
for program comments.

Sum immediate constants into r0.


%    			          // Begin code section
// LOAD_IMMEDIATE r0<- 3  
0: 3			          // values can be decimal..
1: 000010 00   		          //   .. or binary

// LOAD_IMMEDIATE r1<- 2  
2: 2
3: 000010 01

// ADD r0 <- r0 + r1      
4: 00 01 0000		    // binary values can have spaces
5: 000001 00  
       
// HALT                   
10: 0                          // Should now have 5 in r0      
11: 000011 00

// End


Notes: