/* Author : Rick van der Zwet * S-number : 0433373 * Version : $Id: sim.c 365 2007-12-03 08:54:04Z rick $ * Copyright : FreeBSD Licence * Description : MIPS simulator. Main module */ #include #include #include #include "sim.h" #include "alu.h" #include "memory.h" #include "control.h" #include "constant.h" /* Allow printing of diagnostics */ void _print_diag(const int round) { fprintf(stderr, "===TAG ROUND %i====\n", round); fprintf(stderr, "a : %u\n", a); fprintf(stderr, "b : %u\n", b); fprintf(stderr, "c : %u\n", c); fprintf(stderr, "temp : %u\n", temp); fprintf(stderr, "temp2 : %u\n", temp2); fprintf(stderr, "pc : %u\n", pc); fprintf(stderr, "mar : %u\n", mar); fprintf(stderr, "mdr : %u\n", mdr); fprintf(stderr, "ir : %u\n", ir); fprintf(stderr, "imm : %u\n", imm); fprintf(stderr, "constant : %u\n", constant); fprintf(stderr, "mpc : %u\n", mpc); } int main () { fprintf(stderr, "===SIMULATION===\n"); fprintf(stderr, "===INIT===\n"); /* Initiate control */ control_init(); /* Read memory from stdin */ readmem(); /* Limit calls to 10000 to make debugging possible */ int cycles = 0; for (;cycles < 10000; cycles++) { if (mpc == 43) /* Break line, means end */ break; /* Disable if you do not want the verbose outpt */ _print_diag(cycles); /* execute command */ set_signals(); find_new_mPC(); } /* Dump memory and print diag */ fprintf(stderr, "===BEGIN MEMORYDUMP===\n"); writemem(); fprintf(stderr, "====END MEMORYDUMP====\n"); fprintf(stderr, "Number of microinstructions : %i\n", cycles); fprintf(stderr, "Student: Rick van der Zwet\n"); fprintf(stderr, "StudentNumber: 0433373\n"); fprintf(stderr, "===END===\n"); return(EX_OK); }