fork download
  1. /**** This is the Mic-1 linker ****/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #define HEADERS 1
  8. #define NO_HEADERS 0
  9.  
  10. typedef struct nament{
  11. char name[26];
  12. int addr;
  13. struct nament *next;
  14. }SYMTABENTRY;
  15.  
  16.  
  17. void add_symbol(char * symbol, int line_number);
  18. void generate_code(int);
  19. void print_first_pass(int);
  20. void append_table(void);
  21. void dump_table(void);
  22.  
  23.  
  24. SYMTABENTRY *symtab = NULL;
  25. FILE *p1, *p2;
  26. char cstr_12[13];
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30. int i, start, pc_offset=0, pc=0;
  31. int linum=0, object_file=0, dump_tab=0;
  32. int line_number, new_pc;
  33. char instruction[18];
  34. char symbol[26];
  35.  
  36. /***
  37. for(i=0; i<argc; i++){
  38. printf("arg %d is %s\n", i, argv[i]);
  39. }
  40. ***/
  41.  
  42. if(argc > 1 && (strcmp(argv[1], "-s") == 0)) dump_tab = linum = 1;
  43. else if(argc > 1 && (strcmp(argv[1], "-o") == 0)) object_file = 1;
  44.  
  45. if(dump_tab == 1 | object_file == 1)start=2;
  46. else start = 1;
  47.  
  48. p1 = fopen("/tmp/passone", "w+");
  49. unlink("/tmp/passone");
  50.  
  51. for(i=start; i<argc; ++i){
  52. if((p2 = fopen(argv[i], "r")) == NULL){
  53. printf("ERROR: cannot open file %s\n", argv[i]);
  54. exit(6);
  55. }
  56. while(fscanf(p2,"%d %s", &pc, instruction) != EOF){
  57. if(pc == 4096)break;
  58. new_pc = pc + pc_offset;
  59. symbol[0] = '\0';
  60. if(instruction[0] == 'U'){
  61. fscanf(p2, "%s", symbol);
  62. }
  63. fprintf(p1, " %d %s %s\n", new_pc, instruction, symbol);
  64. }
  65. while(fscanf(p2,"%s %d",symbol, &line_number) != EOF){
  66. add_symbol(symbol, line_number+pc_offset);
  67. }
  68. pc_offset = new_pc + 1;
  69. fclose(p2);
  70. }
  71.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:45:14: warning: suggest parentheses around comparison in operand of ‘|’ [-Wparentheses]
  if(dump_tab == 1 | object_file == 1)start=2;
     ~~~~~~~~~^~~~
prog.c:49:9: warning: implicit declaration of function ‘unlink’ [-Wimplicit-function-declaration]
         unlink("/tmp/passone");
         ^~~~~~
prog.c:70:2: error: expected declaration or statement at end of input
  }
  ^
stdout
Standard output is empty