Example #1
0
// Main program: Initialize the cpu, read initial memory values,
// and execute the read-in program starting at location 00.
//
int main(void) {
	printf("*** STUB *** CS 350 Lab 7, Weicheng Huang\n");
	initCPU();
	readMemory();

	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(isEnd==0){
		printf("%s", prompt);
		fgets(command, sizeof command, stdin);		// Read past end of current line.

		if(command[0] == 'q'){
			isEnd = 1;
		}else if(command[0] == 'h'||command[0]=='?'){
			helpMsg();
		}else{
			isEnd=instruction_cycle();
		}
	
	}

	
	

	printf("\nRegisters:\n");
	dumpRegisters(regs);

	printf("\nMemory:\n");
	dumpMemory(mem);
}
Example #2
0
//
//	int regs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//	int mem[100] = { 0 }; // Careful: Leading 0s in constants indicates octal nbr
//	int isEnd = 0;
//	int pc;
//	int ir;
//	int opcode;//operation code
//	int radd;//register address
//	int mmadd;//memory address
// Main program: Initialize the cpu, read initial memory values,
// and execute the read-in program starting at location 00.
//
int main(void) {
  printf(" ******************** STUB ********************\n ");
	printf("Lab9 CS350 Author:Weicheng Huang\n");
	CPU c;
	initCPU(&c);
	readMemory(&c);

	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(c.running==1){
		printf("%s", prompt);
		fgets(command, sizeof command, stdin);		// Read past end of current line.

		if(command[0] == 'q'){
			c.running = 0;
		}else if(command[0] == 'h'||command[0]=='?'){
			helpMsg();
		}else{
			c.running=instruction_cycle(&c);
		}
	
	}

	
	

	printf("\nRegisters:\n");
	dumpRegisters(&c);

	printf("\nMemory:\n");
	dumpMemory(&c);
}
Example #3
0
// Main program: Initialize the cpu, read initial memory values,
// and execute the read-in program starting at location 00.
//
int main(void) {
	printf("CS 350 Lab 8, Raman Walwyn-Venugopal\n");
	initCPU();
	readMemory();
	char prompt[]="> ";
	printf("\nBeginning execution:\n");
	printf("At the %sprompt, press return to execute the next instruction\n", prompt);
	printf("(or d to dump registers and memory, q to quit, or h or ? for help)\n");

	char command[80];       // User inputted command line
	char cmd_char;          // 'q' for quit etc.
	int simulator_quit = 0; // Have we seen simulator quit command?
	int nbr_read;           // Number of items read by sscanf
	int commands_done=0;  
	char c;
	while (!commands_done) {
		printf("%s", prompt);
		fgets(command, sizeof command, stdin);   // Read through end of current line.
		//nbr_read = sscanf(command, "%c", &cmd_char); 

		
		if (strcmp(command,"h\n") == 0 || strcmp(command,"?\n")==0){
		    helpMsg();
		  }
		else if (strcmp(command, "d\n")==0){
		    dumpControlUnit(pc, ir, regs);
		    dumpMemory(mem);
		  }
		else if (strcmp(command,"q\n")==0){
		    commands_done=1;
		  }
		  else if (isdigit(command[0])){
		    int cycles=atoi(command);
		    int d;
		    for (d=0;d<cycles;d++){
		      instruction_cycle();
		      
		    }
		  }
		  else if(strcmp(command, "\n")==0){
		    instruction_cycle();
		  }
		  else{
		    printf("Error! Please enter an appropiate value or h for help\n");
		    
		  }
	}
	
	dumpControlUnit(pc, ir, regs);
	dumpMemory(mem);
	printf("GOODBYE!\n");
}
int main(void)
{
	char input;
    int counter = 0;
    
    printf("CS 350 Lab 8, Jamal Kharrat\nSDC Simulator Framework\n\n");
	initCPU();
	readMemory();
    
	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[] = "> ";
	printf("%s", prompt);
	char command[80];
	fgets(command, sizeof command, stdin);	// Read past end of current line.
    
	do
    {
        scanf("%c", &input);
        if(input == '\r' | input == '\n')
        {
            instruction_cycle();
            printf("%s", prompt);
            counter++;
        }
        else if(input == 'q')
            printf("Quitting\n");   // display quiting message
        
        else if(input == 'h')      
            helpMsg();              // call help message
        
        else
        {
            printf("Invalid Input, try again: ");
            break;
        }
    }
    while (input != 'q' & counter < 10);
    
    
	printf("\nRegisters:\n");
	dumpRegisters(regs);
    
	printf("\nMemory:\n");
	dumpMemory(mem);
}
Example #5
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(void)
{
	int memCounter = 0;
    char input;
    int numCountRef, firstNumRef, secondNumRef, intRestRef;
    
    printf("CS 350 Lab 8, Andrey Danilkovich\nFull SDC Simulator\n\n");
	initCPU();
	readMemory();
    
	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[] = "> ";
	printf("%s", prompt);
	char command[80];
	fgets(command, sizeof command, stdin);	// Read past end of current line.
    
    scanf("%c", &input);
    
	do
    {
        while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear \n from a char */ } // clear out the extra space after the char
        
        numCountRef = getcount(mem, memCounter);
        firstNumRef = getfirst(mem, memCounter, numCountRef);
        secondNumRef = getsecond(mem, memCounter, numCountRef);
        intRestRef = getrest(mem, memCounter, numCountRef);
        
        if(firstNumRef == 0)
        {
            memCounter++;
        }
        else if(input == '\r' | input == '\n')
        {
            instruction_cycle(mem, regs, memCounter);
            memCounter++;
            printf("%s", prompt);
            scanf("%c", &input);
            
            if(firstNumRef == 8 & regs[secondNumRef] > 0)
            {
                memCounter = intRestRef;
            }
            
        }
        else if(input == 'h')
        {
            helpMsg();              // call help message
            printf("%s", prompt);
            scanf("%c", &input);
        }
        else if(input == 'q')
        {
            printf("Quitting program.\n");
        }
        else
        {
            printf("Unknown command; ignoring it.\n");
            printf("%s", prompt);
            scanf("%c", &input);
        }
        
    }
    while (memCounter != 99 & input != 'q');
    
    // Finish Program
    // Print Halting message, diplay registers and memory
    printf("At 00 instr 0 0 00: HALT\n\nHalting\n");
	printf("\nRegisters:\n");
	dumpRegisters(regs);
    
	printf("\nMemory:\n");
	dumpMemory(mem);
}
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;
}
Example #10
0
int main(int argc, char *argv[]){
	
	char cantidad[13]="0";
	char monedaDestino[10]="0", monedaOrigen[10]="0";
	char pLink[1000]="h";
	FILE *pArchivo;
	FILE *pDatos;
	char *dir="data.txt";
	char busca[20000]="0";
	char texto[20]="0";
	char tanteo='>';
	int i,temp,posIni,posFin;
	CURL *curl;
	
	/****************Primera parte**************/
	if(argc==2 && strcmp(argv[1],"--help")==0)
	{
		helpMsg();
		return 0;
	}
	else if(argc==2 && strcmp(argv[1],"--info")==0)
	{
		infoMsg();
		return 0;
	}
	if(argc==4)
	{
		for(i=0;i<strlen(argv[1]);i++)
		{
			if(isdigit(argv[1][i])!=0)
				cantidad[i]=argv[1][i];
		}
		for(i=0;i<strlen(argv[2]);i++)
		{
			monedaOrigen[i]=argv[2][i];
		}
		for(i=0;i<strlen(argv[3]);i++)
		{
			monedaDestino[i]=argv[3][i];
		}
	}
	else
	{
		badArgs();
		return 0;
	}
	
	concatenarLink(pLink,a,cantidad,b,monedaOrigen,c,monedaDestino);
	
	pArchivo=fopen(dir,"r");
	
	/****************Segunda parte**************/
	pDatos=fopen(dir,"w");

	curl = curl_easy_init();
	cURLfuncion(pDatos,pLink);
	curl_easy_cleanup(curl);
	
	fclose(pDatos);
	
	/**Pasar texto a arreglo**/
	crearArrayBusca(pArchivo,busca);
	
	/**Buscar numero**/
	for(i=0;i<sizeof(busca);i++)
	{
		if(busca[i]==tanteo)
		{
			temp=i;
			if(busca[temp-1]=='d' && busca[temp-2]=='l' && busca[temp-3]=='b')
				posIni=temp+1;
		}
		
		if(busca[i]==monedaDestino[0] && busca[i+1]==monedaDestino[1] && busca[i+2]==monedaDestino[2])
		{
			posFin=i-1;
		}
	}
	
	/**Pasar numero a arreglo**/
	resultadoEncontrado(busca,texto,posIni,posFin);
	
	/**Imprimir resultado**/
	printf("\n%s %s = %s %s\n\n",cantidad,monedaOrigen,texto,monedaDestino);
	
	fclose(pArchivo);
	
	return 0;
}
Example #11
0
//---------------------------------------------------------------------------
void procArguments(int argc, char** argv)
{
	const char* configFilename = NULL;

	int listenPort = -1;
	TinyString logLevel;

	bool debugMode = false;
	
	int c;
	while ((c = getopt(argc, argv, ":hdl:p:")) != -1) 
	{
		switch(c) 
		{
		case 'd':
			debugMode = true;
			break;

		case 'p':
			listenPort = atoi(optarg);
			break;

		case 'l':
			logLevel = optarg;
			break;

		case ':':
			printf("-%c is need more value\n", optopt);
			helpMsg(argv[0]);
			exit(0);
			break;

		case '?':
			if(optopt == '-')
			{
				if(strcmp(argv[optind-1], "--help") == 0)
				{
					helpMsg(argv[0]);
					exit(0);
				}
			}
			else
			{
				printf("Unknown arg %c\n", optopt);
				helpMsg(argv[0]);
				exit(0);
			}

		case 'h':
			helpMsg(argv[0]);
			exit(0);

		default:
			helpMsg(argv[0]);
			exit(0);
		}
	}

	if(optind < argc) 
	{
		configFilename = argv[optind];
		optind++;
	}

	if(configFilename == NULL)
		configFilename = defaultConfigFilename;

	if(initConfig(configFilename) < 0)
	{
		printf("컨피그 파일의 존재 및 설정값을 다시 확인해 주세요.\n");
		exit(0);
	}

	if(debugMode)
	{
		Config::instance()->process.daemon = false;
		Config::instance()->log.outputType = LOT_STDOUT;
		Config::instance()->log.level = LLT_MEDIUM;
	}

	if(!logLevel.isEmpty())
	{
		if(logLevel == "HIGH" || logLevel=="4")
		{
			Config::instance()->log.level = LLT_HIGH;
		}
		else if(logLevel == "MEDIUM" || logLevel=="3")
		{
			Config::instance()->log.level = LLT_MEDIUM;
		}
		else if(logLevel == "LOW" || logLevel=="2")
		{
			Config::instance()->log.level = LLT_LOW;
		}
		else if(logLevel == "VERYLOW" || logLevel == "1")
		{
			Config::instance()->log.level = LLT_VERYLOW;
		}
	}

	if(listenPort > 0)
		Config::instance()->network.listenPort = listenPort;
}