int main(int argc, char *argv[]) { int object_file = 0; if (argc > 1 && (strcmp(argv[1], "-o") == 0)) { object_file = 1; } char *passone = "/tmp/masm.passone"; p1 = fopen(passone, "w+"); unlink(passone); generate_first_pass(); if (object_file) { print_first_pass(); append_table(); } else { generate_code(); dump_table(); } return 0; }
int main( int argc, char* argv[]){ int i, start, pc_offset = 0, pc = 0; int linum = 0, object_file = 0, dump_tab = 0; int line_number, new_pc; char instruction[18]; char symbol[26]; /*Check for options*/ if(argc > 1 && (strcmp(argv[1], "-s") == 0)){ dump_tab = linum = 1; } else if( argc > 1 && (strcmp(argv[1], "-o") == 0 )){ object_file = 1; } /* Execute options if they exist */ if((dump_tab == 1) | (object_file == 1)){ start = 2; } else { start = 1; } /* Create new file and remove name */ p1 = fopen("/tmp/daedalus", "w+"); unlink("/tmp/daedalus"); for(i = start; i < argc; i++){ /* Check that we can open the file */ if((p2 = fopen(argv[i], "r")) == NULL){ printf("Cannot open file named: %s", argv[i]); exit(2); } while(fscanf(p2, "%d %s", &pc, instruction) != EOF){ /* Check for end of program */ if(pc == 4096) break; new_pc = pc + pc_offset; symbol[0] = '\0'; /* Line not cooked yet */ if(instruction[0] == 'U'){ fscanf(p2, "%s", symbol); } fprintf(p1, " %d %s %s \n", new_pc, instruction, symbol); } while(fscanf(p2, "%s %d", symbol, &line_number) != EOF){ add_symbol(symbol, line_number + pc_offset); } pc_offset = new_pc + 1; fclose(p2); } /* if this option was on do it */ if(object_file){ print_first_pass(NO_HEADERS); printf("4096 x\n"); append_table(); return 0; } /* do this option if it was on */ if(linum){ print_first_pass(HEADERS); } generate_code(linum); return 0; }