📄 pass1.c
字号:
for(i=0;i<num;i++) { if(i==0) { strcpy(ins,newtokens[i]); strcat(ins," "); } else { strcat(ins,newtokens[i]); if(i<num-1) strcat(ins,","); } // else if(i<num-1) // strcat(ins,","); //strcat(ins,newtokens[i+1]); } for (i=0;i<=0xFF;i++) { if(!strcasecmp(instructions[i].mnemonic,ins )) { found_flag = 1; // this is the code to test for 2 byte ins... break ; } } }/////////// } if(found_flag==1 ) { info->hex_array[0] = instructions[i].hex_code ; if ( instructions[i].hex_code==0x2 || instructions[i].hex_code==0x12 ) //for ljmp or lcall instructions we must break up the { // one 2-byte operand into // two 1-byte operands ;-) info->hex_array[2] = info->hex_array[1] % 0x100 ; //a very clever way to avoid using a temp variable... info->hex_array[1] = info->hex_array[1] / 0x100 ; //by generating the ls-byte first and then the ms-byte... } info->nobytes = instructions[i].nobytes ; //return hex_array ; //hex_array = //info = &instructions[i] ; return info ; } /* else { // do some stuff here to match a 3 byte instruction... // and break the loop immediately if a match occurs... } if(found_flag==1) { //return hex_array ; //info = &instructions[i]; return info ; } */ // we have reached here means that all possible ins have been searched..so there must be an error... else // this should come after all instructions are checked... { gas51_errno = 4 ; // 4 is the error code for illegal instruction... gas51_perror(); //exit(1); } //return 0;}void push (struct gas51_file_info *temp_info ) { gas51_file_info_stack[gas51_stack_index] = *(temp_info) ; // hope this copies the whole structure... gas51_stack_index++ ; }struct gas51_file_info * pop(void){ struct gas51_file_info *temp_info ; gas51_stack_index--; temp_info = &(gas51_file_info_stack[gas51_stack_index]); return temp_info ; }int get_tokens(char t_addr[][10],char *instruction){ unsigned int i,j,k; char buff[10]; i=0; j=0; k=1; //puts(instruction); // this was really VERY ANNOYING....;-{ finding this line... while(instruction[i]!=' ' ) //at this point we may be sure that only a sinle space will be between 1st and 2nd token... { buff[j]=instruction[i] ; i++; j++; } buff[j] = '\0' ; // terminating buff with a trailing NULL... strcpy(t_addr[0],buff); //first token gone...two more to go... i++; //to get over the single space... j=0 ; //reiniting j for a new buff... while(1){ if(instruction[i]=='\n' || instruction[i]=='\0') { buff[j] = '\0' ; strcpy(t_addr[k],buff); if(strlen(buff)) //increment only if buff is non empty... k++; break ; } if(instruction[i]==',' || instruction[i]==' ' || instruction[i]=='\t') { buff[j] = '\0' ; strcpy(t_addr[k],buff); if(strlen(buff)) // increment only if buff is non empty... k++; i++; j=0; } else { buff[j]=instruction[i]; i++; j++; }} /* while(1) { } */ /* while(instruction[i]!=',' ) { buff[j] = instruction[i]; i++; j++; } buff[j] = '\0' ; //terminating buff with a trailing NULL... strcpy(t_addr[1],buff); //second token gone...one more to go... i++; j=0; while(instruction[i]!='\n') { buff[j] = instruction[i]; i++; j++; } */ return k ; // returning the total number of tokens found... }int isstandard(char *token){ //int retval=0 ; if(!strcasecmp(token,"ajmp")) return 1 ; else if(!strcasecmp(token,"ljmp")) return 1; else if(!strcasecmp(token,"inc")) return 1; else if(!strcasecmp(token,"jbc")) return 1; else if(!strcasecmp(token,"acall")) return 1; else if(!strcasecmp(token,"lcall")) return 1; else if(!strcasecmp(token,"dec")) return 1; else if(!strcasecmp(token,"jb")) return 1; else if(!strcasecmp(token,"add")) return 1; else if(!strcasecmp(token,"jnb")) return 1; else if(!strcasecmp(token,"addc")) return 1; else if(!strcasecmp(token,"jc")) return 1; else if(!strcasecmp(token,"orl")) return 1; else if(!strcasecmp(token,"jnc")) return 1; else if(!strcasecmp(token,"anl")) return 1; else if(!strcasecmp(token,"jz")) return 1; else if(!strcasecmp(token,"xrl")) return 1; else if(!strcasecmp(token,"jnz")) return 1; else if(!strcasecmp(token,"mov")) return 1; else if(!strcasecmp(token,"sjmp")) return 1; else if(!strcasecmp(token,"subb")) return 1; else if(!strcasecmp(token,"cpl")) return 1; else if(!strcasecmp(token,"cjne")) return 1; else if(!strcasecmp(token,"push")) return 1; else if(!strcasecmp(token,"clr")) return 1; else if(!strcasecmp(token,"xch")) return 1; else if(!strcasecmp(token,"pop")) return 1; else if(!strcasecmp(token,"setb")) return 1; else if(!strcasecmp(token,"djnz")) return 1; else if(!strcasecmp(token,"a")) return 1; /* else if(!strcasecmp(token,"b")) return 1; else if(!strcasecmp(token,"@r0")) return 1; else if(!strcasecmp(token,"@r1")) return 1; else if(!strcasecmp(token,"r0")) return 1; else if(!strcasecmp(token,"r1")) return 1; else if(!strcasecmp(token,"r2")) return 1; else if(!strcasecmp(token,"r3")) return 1; else if(!strcasecmp(token,"r4")) return 1; else if(!strcasecmp(token,"r5")) return 1; else if(!strcasecmp(token,"r6")) return 1; else if(!strcasecmp(token,"r7")) return 1; else if(!strcasecmp(token,"psw")) return 1; else if(!strcasecmp(token,"dptr")) return 1; else if(!strcasecmp(token,"p0")) return 1; else if(!strcasecmp(token,"p1")) return 1; else if(!strcasecmp(token,"p2")) return 1; else if(!strcasecmp(token,"p3")) return 1; else if(!strcasecmp(token,"ip")) return 1; else if(!strcasecmp(token,"ie")) return 1; else if(!strcasecmp(token,"tmod")) return 1; else if(!strcasecmp(token,"tcon")) return 1; else if(!strcasecmp(token,"th0")) return 1; else if(!strcasecmp(token,"tl0")) return 1; else if(!strcasecmp(token,"th1")) return 1; else if(!strcasecmp(token,"tl1")) return 1; else if(!strcasecmp(token,"scon")) return 1; else if(!strcasecmp(token,"sbuf")) return 1; else if(!strcasecmp(token,"pcon")) return 1; else if(!strcasecmp(token,"c")) return 1; else if(!strcasecmp(token,"rs0")) return 1; else if(!strcasecmp(token,"rs1")) return 1; *//* else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; else if(!strcasecmp(token,"")) return 1; */ else return 0; //means the token is not a keyword or a standard token...but an address,data,sfr or label} int islabel(char *token){ if(( *(token+0))=='_' ) return 1; //label may start with an underscore... else if( isalpha( ( *( token+0) ) ) ) return 1; //label may begin witn an alphabet...then succeeding characters are irrelevant... else if( isdigit( ( *( token+0) ) ) ) return 0; //label cannot start with a digit...this will be interpreted as a misformed number,hex or otherwise...}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -