issue with IAS machine instruction cycle simulator in C programming

This is a discussion on issue with IAS machine instruction cycle simulator in C programming within the C Programming forums, part of the General Programming Boards category; hello everyone i've got this assignement where i have to demonstrate the fetch and instruction cycle of an IAS machine ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    72

    issue with IAS machine instruction cycle simulator in C programming

    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:
    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);
     	}
    
     	}
    
    	
    }
    for a text file that is as follows :
    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
    Last edited by overlord21; 03-01-2010 at 07:48 AM.

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    72
    should the functions be handled this way?
    void execute_instruct(){

    switch (IR )
    {
    case 0xA:
    printf("==> Execute Instruction LOAD MQ\n");
    load_MQ(verbose);
    break;
    case 0x9:
    printf("==> Execute Instruction LOAD MQ_M(x)\n");
    load_MQ_Mx(memory, instructions, verbose);
    break;
    case 0x21:
    printf("==> Execute Instruction STOR M(x)\n");
    stor_Mx(memory, instructions, verbose);
    break;
    case 0x1:
    printf("==> Execute Instruction LOAD M(x)\n");
    load_Mx(memory, instructions, verbose);
    break;
    case 0x2:
    printf("==> Execute Instruction LOAD -M(x)\n");
    load_mMx(memory, instructions, verbose);
    break;

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Well you could break up you main into a few functions, like

    - loadProgramIntoMemory
    - executeProgramInMemory

    You can test the second one quite easily just by manually adding a few instructions to the memory, then seeing what happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    First of all state the problem as clearly as possible. Can't figure out from the input file what part is the opcode and what part is the operand, so provide more information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Will my memory leak? --school project
    By steals10304 in forum C++ Programming
    Replies: 10
    Last Post: 02-24-2010, 02:04 PM
  2. Simulator
    By MasterAchilles in forum C Programming
    Replies: 10
    Last Post: 11-30-2008, 09:31 PM
  3. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 07:02 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21