static void statement() { int index = iselect; int index2; instruction_display(apc - 1, 1, flag['l'-'a']); printf("%6.6x %8.8x\n", psr, apc - memory.array); instruction_display(apc, 6, flag['l'-'a']); while (index < (iselect | 24)) { print_register_row(index); putchar('\n'); index += 8; } index = sp; printf("[%6.6x]->", index); index2 = 7; while (index2--) { if (index > 255) break; printf(" %6.6x", _register[index++]); } printf("\n "); index2 = 8; while (index2--) { if (index > 255) break; printf(" %6.6x", _register[index++]); } printf("\n "); index2 = 8; while (index2--) { if (index > 255) break; printf(" %6.6x", _register[index++]); } putchar('\n'); }
int main(int argc, char* argv[]) { int status = 0; /** Part 0: argument setting **/ glb_argc = argc; glb_argv = argv; argument_setting(); /** Part 1: Initialization **/ initialization(); /** Part 2: Read the data image into the D-disk. **/ read_Dimage_into_Ddisk(); /** Part 3: Read the instruction image into the I-disk. **/ read_Iimage_into_Idisk(); /** Part 4: Execute the instructions. **/ /* open the files */ fout = fopen("snapshot.rpt", "w"); //ferr = fopen("error_dump.rpt", "w"); file_open_failure_process( fout, "snapshot.rpt" ); //file_open_failure_process( ferr, "error_dump.rpt" ); /* start executing */ printf("#5 The following is the tracing of the execution.\n\n"); cycle = 0; while(1) { /* PC validity check and instruction fetching setting */ if( pc<0 || pc>1023 || pc%4!=0 ) testcase_invalid_process("The program counter is not on a valid position."); /* register data display */ register_data_display(cycle); cycle++; /* cycle overflows interruption */ if( cycle>500002 ) testcase_invalid_process("The process has run for too many cycles."); /* find instruction */ find_instruction(); /* register index setting */ instruction_decomposition(fetched_instruction); /* instruction display */ instruction_display(); /* mapping from instruction bit to real operation */ status = choose_instruction_to_execute(fetched_instruction); /* avoid write 0 error */ reg[0] = 0; /*error handling */ if( status==1 ) break; /*getchar();*/ } hit_miss_situation_write_to_file(); fclose( fout ); //fclose( ferr ); return 0; }