Ejemplo n.º 1
0
int emu_step() {
    instruction in;
    int i;
	char *state;
	int result;

	in.instr = read_insrtuction(memory.R[7]);
	memset(disas, '0', LEN);
	memset(reg, '0', LEN);
	
	for (i = 0; i < COUNT; i++) {
        if (check_instr(i, in)) {
			sprintf(disas, "%06o %s", in.instr, table[i].assembler(in));

			result = handle_callback(i, in);
			switch(result) {
			case EX:
				state = "Execution";
				break;
			case HLT:
				state = "Completed";
				break;
			default:
				state = "Unknown error";
			}
			
			set_reg(state);

			return in.instr;
        }
    }
	sprintf(disas, "%s", "UNKNOWN COMMAND");
	set_reg("ERROR UNKNOWN OPCODE");
    return UNKNOWN_COMMAND;
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
    const char  *filename;
    int         i;

    /* Process command line */

    if (argc < 2) {
        usage();
        exit(EXIT_FAILURE);
    }

    for (i = 1; i < argc - 1; i++) 
        if (streq(argv[i],"-i"))
            print_instrs = TRUE;
        else if (streq(argv[i],"-q"))
            quiet = TRUE;
        else if (streq(argv[i],"-s"))
            statistics = TRUE;
        else
            usage();
    
    filename = argv[argc-1];

    ozyyin = fopen(filename, "r");
    ozyyfile = filename;
    ozyylinenum = 1;
    if (ozyyin == NULL) {
        perror(filename);
        exit(EXIT_FAILURE);
    }

    if (ozyyparse() != 0) {
        /* the error message will already have been printed */
        exit(EXIT_FAILURE);
    }

    init_all_regs();
    init_stack();

    pc = 0;
    cur_instr = 0;
    while (! halted && ! found_error) {
        if (! check_instr(pc)) 
            report_error_and_exit("execution fell out of the program");
        next_pc = pc + 1;
        execute_instr_at_pc();
        cur_instr++;
        pc = next_pc;
    }

    if (found_error) 
        exit(EXIT_FAILURE);

    if (statistics) {
        printf("Number of instructions in program code: %d.\n", next_instr);
        printf("Number of instructions executed: %d.\n", cur_instr);
    }

    return 0;
}