// -------------------- MAIN PROGRAM --------------------
//
// The main program creates and initializes a CPU, loads a program,
// and executes it step by step (until it halts or the user quits).
// The CPU is dumped before and after executing the program
//
int main() {
	// Create and initialize the  CPU, read initial memory, dump CPU
	//
	CPU cpu_struct, *cpu;
	cpu = &cpu_struct;
	init_CPU(cpu);
	printf("Jamal Kharrat Full LC-3 simulator\n");


	/* *** STUB *** */
	return 0;
}
Exemple #2
0
// -------------------- MAIN PROGRAM --------------------
//
int main() {

	// Declare and initialize the CPU
	//
	//int temp = bitshift(0x0ff9,11,9,1);
//	printf("temp = %d %x\n",temp,temp);

  printf(" ******************** STUB ********************\n ");
  printf("Lab10 CS350 Author:Weicheng Huang\n");
  CPU cpu;
  init_CPU(&cpu);
  Address end =  readfile(&cpu);
  Address origin  = cpu.pgm_counter;
	printf("origin = %x ; end = %x \n",origin,end);
	printf("\nRegisters:\n");
	dump_registers(&cpu);

	printf("\nMemory:\n");
	dump_memory(&cpu,cpu.pgm_counter,end,0);
  
	printf("\nBeginning execution:\n");
	printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n");
	char prompt[] = "> ";
	char command[80];
	fgets(command, sizeof command, stdin);	
	while(cpu.running==1){
		printf("%s", prompt);
		fgets(command, sizeof command, stdin);		// Read past end of current line.
		char op = command[0];		
			  unsigned int from=0;
				unsigned int too = 0;
		switch(op){
			case 'q':
				cpu.running = 0;
				break;		
			case 'h':
				helpMsg();
				break;
			case '?':
				helpMsg();
				break;
			case 'r':
				printf("\nRegisters:\n");
				dump_registers(&cpu);
				break;
			case 'm':
			  sscanf(command,"m %x %x",&from,&too);
			  dump_memory(&cpu,(Address)from,(Address)too,1);
			  break;
			default:
			  instruction_cycle(&cpu);
			  break;
		}
	}
/*
		if(command[0] == 'q'){
			c.running = 0;
		}else if(command[0] == 'h'||command[0]=='?'){
			helpMsg();
		}else{
			c.running=instruction_cycle(&c);
		}
*/


	
	

	printf("\nRegisters:\n");
	dump_registers(&cpu);

	printf("\nMemory:\n");
	dump_memory(&cpu,origin,end,1);
	printf("\nAll done!\n");
}
// -------------------- MAIN PROGRAM --------------------
//
// The main program creates and initializes a CPU, loads a program,
// and executes it step by step (until it halts or the user quits).
// The CPU is dumped before and after executing the program
//
int main() {
	// Create and initialize the  CPU, read initial memory, dump CPU
	// CPU cpu_struct, *cpu;
	// cpu = &cpu_struct;
		

	printInf();
	  CPU cpu;
  init_CPU(&cpu);
  Address end =  readfile(&cpu);
  Address origin  = cpu.pgm_counter;
        printf("origin = %x ; end = %x \n",origin,end);
        printf("\nRegisters:\n");
        dump_registers(&cpu);

        printf("\nMemory:\n");
        dump_memory(&cpu,cpu.pgm_counter,end,0);
  
        printf("\nBeginning execution:\n");
        printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n");
        char prompt[] = "> ";
        char command[80];
        fgets(command, sizeof command, stdin);        
        while(cpu.running==1){
                printf("%s", prompt);
                fgets(command, sizeof command, stdin);                // Read past end of current line.
         
               char op = command[0];                
                          unsigned int from=0;
                                unsigned int too = 0;
                switch(op){
                        case 'q':
                                cpu.running = 0;
                                break;                
                        case 'h':
                                helpMsg();
                                break;
                        case '?':
                                helpMsg();
                                break;
                        case 'r':
                                printf("\nRegisters:\n");
                                dump_registers(&cpu);
                                break;
                        case 'd':
                          sscanf(command,"m %x %x",&from,&too);
                          dump_memory(&cpu,(Address)from,(Address)too,1);
                          break;
                        default:
                          instruction_cycle(&cpu);
                          break;
                }
        }
/*
                if(command[0] == 'q'){
                        c.running = 0;
                }else if(command[0] == 'h'||command[0]=='?'){
                        helpMsg();
                }else{
                        c.running=instruction_cycle(&c);
                }
*/


        
        

        printf("\nRegisters:\n");
        dump_registers(&cpu);

        printf("\nMemory:\n");
        dump_memory(&cpu,origin,end,1);
        printf("\nAll done!\n");
}
int main()
{
	// Declare and initialize the CPU
	// ..
    CPU cpu;
    init_CPU(&cpu);
    // ..   
    
    printf("CS 350 Final Project, Andrey Danilkovich\nLC3 Simulator\n\n");
    printf("File to read from: ");
    
    
    char filename[80];
    char input = 0;
    char prompt[] = "> ";
    
    char memoryInput;
    int hex1, hex2;
    
    
    scanf("%s", filename);
    FILE *file = fopen ( filename, "r" );
    if ( file != NULL )
    {
        printf("** %s contains **\n\n", filename);
        char line [ 128 ]; /* or other suitable maximum line size */
        while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
        {
            fputs ( line, stdout ); /* write the line */
        }
        fclose ( file );
    }
    else
    {
        perror ( filename ); /* why didn't the file open? */
        
        printf("Possible file names:\n\nhelloworld.hex\nnegaddr.hex\nprintstring.hex\nrc.hex\nreadchar.hex\nreadstring.hex\n");
        
        return 0;
        printf("\nFile to read from: ");
        scanf("%s", filename);
        
    }

    printf("\nInitial CPU:\n");    
    dump_registers(&cpu);
    
    dump_memory(&cpu, to, from, nonzero_only);
    printf("\n");
    
    
    printf("Beginning execution:\nAt the > prompt, press return to execute the next instruction, q to quit,\nr to dump the registers, m hex#1 hex#2 to dump memory, or h for help.\n");
    

	printf("%s", prompt);
    
    while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ }
    scanf("%c", &input);
    
    
	do
    {
        while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ }
        
        if(input == '\r' | input == '\n')
        {
            instruction_cycle(&cpu);
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if(input == 'h')
        {
            helpMsg();              // call help message
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if (input == 'r')
        {
            printf("*** STUB *** Dump registers\n");
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if(input == 'q')
        {
            printf("Quitting\n");
        }
        else if (input == 'm')
        {
            printf("\tm: ");
            scanf("%c", &memoryInput);
            printf("\thex_n1: ");
            scanf("%d", &hex1);
            printf("\thex_n1: ");
            scanf("%d", &hex2);
            
            while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ }
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else
        {
            printf("Unknown command; ignoring it.\n");
            printf("%s", prompt);
            scanf("%c", &input);
        }
        
    }
    while (input != 'q');  // & cpu->pc != 100
    
    printf("Halting\n");
    
	return 0;
}
int main()
{
	// Declare and initialize the CPU
    CPU cpu;
    init_CPU(&cpu);
    
    //char filename[80];
    char input = 0;
    char prompt[] = "> ";
    
    int counter;        // how many values read from file
    int addr  = 0;
    
    description();  // Call display name and project
    counter = get_memory(&cpu, addr);   // Call function
    
    printf("\nInitial CPU:\n");    
    dump_registers(&cpu);   // Call dump registers function
    
    dump_memory(&cpu, to, from, nonzero_only, counter);
    printf("\n");
    
    
    printf("Beginning execution:\nAt the > prompt, press return to execute the next instruction, q to quit,\nr to dump the registers, m hex#1 hex#2 to dump memory, or h for help.\n");

	printf("%s", prompt);
    
    while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ }
    scanf("%c", &input);
    
    int order = (cpu).memory[0];        // set order for instrction cycle
    
	do
    {
        while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ }
        
        if(input == '\r' | input == '\n')
        {
            instruction_cycle(&cpu, order);
            printf("%s", prompt);
            scanf("%c", &input);
            order++;
        }
        else if(input == 'h')
        {
            helpMsg();              // call help message
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if (input == 'r')
        {
            printf("Dump registers\n");
            dump_registers(&cpu);
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if(input == 'q')
        {
            printf("Quitting\n");
        }
        else if (input == 'm')
        {
            char s[] = "m 01f  359a";
            sscanf(s, "m %hx %hx", &from, &to);
            dump_memory(&cpu, to, from, nonzero_only, counter);
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else
        {
            printf("Unknown command; ignoring it.\n");
            helpMsg();              // call help message
            printf("%s", prompt);
            scanf("%c", &input);
        }
        
    }
    while (input != 'q');  // End loop when user enters q. Previous command - & cpu->pc != 100
    
    printf("Quitting\n");
    printf("Halting\n");
    
    // Final step - Dump registers and Memory
    dump_registers(&cpu);
    dump_memory(&cpu, to, from, nonzero_only, counter);
	return 0;
}