int parse(char inst[],char lab[][55]){ int status; status =1; checkCharacter(inst); status=checkOpcode(inst,lab); printf("%d\n",status); return status; }
void passOne(char *inputFile){ // function performs pass one of the assembler char lineCpy[20]; int idx = 0; FILE *input, *intermediate; input = fopen(inputFile, "r"); intermediate = fopen("intermediate.txt", "w"); printf("\n"); printf("Address\tLabel\tOpcode\tOperand\n"); printf("*******************************\n"); fgets(line,20,input); while(line[0] == '.') fgets(line,20,input); readLine(); if(!strcmp(opcode,"START")) { strcat(operandHex,"0x"); strcat(operandHex,operand); startAddr = strtol(operandHex,NULL,16); LOCCTR = startAddr; address[idx++] = LOCCTR; strcpy(programName,label); while(strlen(programName)!=6) strcat(programName," "); fprintf(intermediate,"%s",line); fgets(line,20,input); while(line[0] == '.') fgets(line,20,input); } else { programName[0]='\0'; startAddr=0x00; LOCCTR=0x00; address[idx++] = LOCCTR; } printf("\n XXXX\t %s\t%s\t %s",label,opcode,operand); while(strcmp(lineCpy,"END")) { readLine(); printf("\n %04X\t %s \t%s\t %s",LOCCTR,label,opcode,operand); if(label[0]!='\0') checkLabel(); checkOpcode(); address[idx++] = LOCCTR; if(label[0]!='\0') fprintf(intermediate,"%s %s %s\n",label,opcode,operand); else fprintf(intermediate,"%s %s\n",opcode,operand); fgets(line,20,input); while(line[0] == '.') fgets(line,20,input); strcpy(lineCpy, line); lineCpy[3] = '\0'; } printf("\n XXXX\t\t%s\n",line); fprintf(intermediate,"%s",line); fclose(intermediate); fclose(input); }