hello everyone i've got this assignement where i have to demonstrate the fetch and instruction cycle of an IAS machine
Until now i've implemented the needed functions
but my issue is regarding the testing i don't how to test the program with files.....
it goes like follows:
for a text file that is as follows :Code:long long int PC, MAR, MQ, AC, MBR[4], IBR[2], IR; int verbose,instruction_line=1; long long int instructions[65536][4]; long long int memory[65536]; int main(){ long long int /*beginingstatement,*/ index, operant, opcode, adress; int i=1, j=0, m, n, counter=0; char exe_mode; FILE *inp; if ( ( inp = fopen( "Input.txt", "r" ) ) == NULL ) { printf( "File could not be opened\n" ); } else { while(index != 11000){ // fscanf(inp, "%x", &beginingstatement); fscanf(inp, "%x%x", &index, &operant); memory[index] = operant; fscanf(inp, "%x%x", &index, &operant); opcode = operant; /* Reading the program and saving it at location M[1] */ while(!feof(inp)){ instructions[i][j] = opcode; fscanf(inp, "%d", &adress); instructions[i][j+1] = adress; counter++; fscanf(inp, "%x", &opcode); if(feof(inp)) break; else{ instructions[i][j+2] = opcode; //printf("%X\n", instructions[i][j+2]); fscanf(inp, "%d", &adress); instructions[i][j+3] = adress; counter++; i++; j=0; fscanf(inp, "%x", &opcode); } } printf("Execute Instruction in\n --Normal Mode(N)\n --Tracing Mode(T)\n-->"); scanf("%c", &exe_mode); if(exe_mode == 'N') verbose = 0; else verbose = 1; PC = 1; for(i=0; i<counter; i++){ if(verbose) printf("==> fetch Instruction %d\n\n", i+1); fetchNextInstruction(); execute_instruct(); } printf("==> The final values of the registers:\n"); printf(" PC = %d\n", PC); printf(" MAR = %d\n", MAR); printf(" MBR = %X\n", MBR[1]); printf(" IBR = "); for(i=0; i<2; i++) printf("%X ", IBR[i]); printf("\n"); printf(" AC = %X\n", AC); printf(" IR = %X\n", IR); printf(" MQ = %X\n", MQ); } } }
10003
940 A
941 2
10001
1 940
5 941
how should the text file look like if considering how the program is supposed to show the cycles



LinkBack URL
About LinkBacks


