int main( int argc, char ** argv ) { FILE * pFile; int i, do_continue; char in_file[MAX_STR+1], out_file[MAX_STR+1], line[MAX_STR+1]; do_continue = i = 0; pFile = NULL; do { printf("Input file? "); fgets( in_file, MAX_STR, stdin ); printf("Output file? "); fgets( out_file, MAX_STR, stdin ); sscanf( in_file, "%s\n", in_file ); sscanf( out_file, "%s\n", out_file ); pFile = fopen( in_file, "r" ); if( pFile == NULL ) return 1; fout = fopen( out_file, "w" ); if( fout == NULL ) return 2; if( init( pFile ) ) goto unable_to_parse; do { fprintf( fout, "c#%d ", cycle ); wb(); mem3(); mem2(); mem1(); ex(); id(); if2(); if1(); /* pretend all stages are happening simultaneously */ fprintf( fout, "\n"); /* move everything down the pipeline */ if( !MEM3_stall ) { WB = MEM3; WB_count = MEM3_count; } if( !MEM2_stall ) { MEM3 = MEM2; MEM3_count = MEM2_count; } if( !MEM1_stall ) { MEM2 = MEM1; MEM2_count = MEM1_count; } if( !EX_stall ) { MEM1 = EX; MEM1_count = EX_count; } if( !ID_stall ) { EX = ID; EX_count = ID_count; } else MEM1 = EMPTY; if( !IF2_stall ) { ID = IF2; ID_count = IF2_count; } if( !IF1_stall ) { IF2 = IF1; IF2_count = IF1_count; ++inst_cycle; } if( flush ) { IF1 = EMPTY; IF2 = EMPTY; ID = EMPTY; EX = EMPTY; flush = FALSE; --inst_cycle; } ++cycle; Registers[0] = 0; /* reset R0 if it was accidently set */ } while( ( (IF1 != EMPTY) || (IF2 != EMPTY) || (ID != EMPTY) || (EX != EMPTY) || (MEM1 != EMPTY) || (MEM2 != EMPTY) || (MEM3 != EMPTY) || (WB != EMPTY) ) ); /* print end status */ print_regs( fout ); print_mem( fout ); unable_to_parse: for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); printf("would you like to run again? "); fgets( line, MAX_STR, stdin ); do_continue = ( line[0] == 'y' || line[0] == 'Y' ) ? 1 : 0; } while( do_continue ); goto end; for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); end: return 0; }
int main(void){ Memory mem(200); int retrieval; for(int i = 0; i < mem.getSize(); i++){ mem.insert(i,i); } printf("\n-------------------------Memory Test--------------------------\n"); printf("\n200 integers have been inserted into Memory from 0 to 199.\n"); mem.dump(); mem.BlockCopy(0,100,99); printf("\nThe first 100 integers have been copied into the last 100 locations.\n"); mem.dump(); retrieval = mem.retrieve(199); printf("\nThe last integer in Memory is"); printf("%3d",retrieval); printf(".\n"); mem.BlockCopy(190, 10, 9); printf("\nThe last ten integers have been copied into location 10.\n"); mem.dump(10, 19); printf("\n-------------------------Overloaded Operators Test--------------------------\n"); Memory mem2; Memory mem3(200); for(int i = 0; i < mem2.getSize(); i++){ mem2[i] = i; } cout << "\n100 integers have been inserted into Memory 2.\n"; cout << mem2; for(int i = 0; i < mem3.getSize(); i++){ mem3[i] = i; } cout << "\n200 integers have been inserted into Memory 3.\n"; cout << mem3; cout << "\nMemory 4 is the Sum of both Memory 2 and Memory 3\n"; Memory mem4 = mem2+mem3; cout << mem4; cout << "\nMemory 5 is a Copy of Memory 4\n"; Memory mem5 = mem4; cout << mem5; cout << "\nMemory 5 is Added to Memory 5\n"; mem5 = mem5 + mem5; cout << mem5; if (mem5!=mem4) cout << "\nMemory 5 does not equal Memory 4\n"; else cout << "\nMemory 5 equals Memory 4\n"; mem5[50] = 99999; int value = mem5[50]; cout << "\n" << value << " has been inserted at location 50 in Memory 5\n"; cout << mem5; return -1; }