void generate_code() { char instruction[18] = {'0'}; int pc = 0, mask = 0, sym_val = 0, old_pc = 0, diff = 0; char symbol[26] = {'0'}; rewind(p1); while (fscanf(p1,"%d %s", &pc, instruction) != EOF) { if ((diff = pc - old_pc ) > 1) { for (int j=1; j<diff; j++) { printf("1111111111111111\n"); } } old_pc = pc; if (instruction[0] == 'U') { fscanf(p1, "%s", symbol); if ((sym_val = get_sym_val(symbol)) == -1) { fprintf(stderr, "no symbol in symbol table: %s\n", symbol); exit(27); } str_n(12, sym_val); for (int i=0; i<12; i++) { instruction[i+5] = cstr_16[i]; } printf("%s\n", &instruction[1]); } else { printf("%s\n", instruction); } } fclose(p1); }
void generate_code(int linum){ /*char linbuf[10];*/ char instruction [18]; int line_number; int pc, mask, sym_val, i, j, old_pc, diff; char symbol[26]; line_number = old_pc = 0; rewind(p1); /*sprintf(linbuf, "%5d: ", line_number);*/ while(fscanf(p1, "%d %s", &pc, instruction) != EOF){ if((diff = pc - old_pc) > 1 ){ for(j = 1; j < diff; j++){ /*sprintf(linbuf, "%5d: ", line_number++);*/ printf("1111111111111111 \n"); } } /* sprintf(linbuf, "%5d: ", line_number++); */ old_pc = pc; if(instruction[0] == 'U'){ fscanf(p1, "%s", symbol); sym_val = get_sym_val(symbol); if(sym_val == -1){ printf("Error no symbol"); exit(3); } /* contains end of instruction */ for(i = 0; i<12; i++){ cstr_12[i] = '0'; } cstr_12[12] = '\0'; mask = 2048; for(i = 0; i < 12; i++){ if(sym_val & mask){ cstr_12[i] = '1'; } mask >>= 1; } for(i = 0; i < 12; i++){ instruction[i + 5] = cstr_12[i]; } printf("%s\n", &instruction[1]); } else {
void generate_code(int linum){ char linbuf[10]; char instruction[18]; int line_number; int pc, mask, sym_val,i, j, old_pc, diff; char symbol[26]; line_number = old_pc = 0; rewind(p1); sprintf(linbuf,"%5d: ", line_number); while(fscanf(p1,"%d %s", &pc, instruction) != EOF){ if((diff = pc - old_pc ) > 1){ for(j=1; j<diff; j++){ sprintf(linbuf,"%5d: ", line_number++); printf("%s1111111111111111\n",(linum ? linbuf: "\0")); } } sprintf(linbuf,"%5d: ", line_number++); old_pc = pc; if(instruction[0] == 'U'){ fscanf(p1, "%s", symbol); if((sym_val = get_sym_val(symbol)) == -1){ fprintf(stderr, "no symbol in symbol table: %s\n", symbol); exit(27); } for(i=0; i<12; i++){ cstr_12[i] = '0'; } cstr_12[12] = '\0'; mask = 2048; for(i=0; i<12; i++){ if(sym_val & mask) cstr_12[i] = '1'; mask >>= 1; } for(i=0; i<12; i++){ instruction[i+5] = cstr_12[i]; } printf("%s%s\n",(linum ? linbuf: "\0"),&instruction[1]); }else