Pass 1 Assembler in c

April 25, 2017 | Author: Ekta Singh | Category: N/A
Share Embed Donate


Short Description

Download Pass 1 Assembler in c...

Description

//input.txt START 200 MOVER AREG , ='5' MOVEM AREG , A LOOP MOVER AREG , A MOVER CREG , B ADD CREG , ='1' LTORG ='5' ='1' NEXT1 SUB AREG , ='1' ORIGIN LOOP+6 MUL CREG , B A DS 2 B DC 3 NEXT2 EQU LOOP END ='1'

//Pass 1 Assembler #include #include #include #include #include //----------------------------------------------------------------------------// char label[4][10]; //To store all words in a line int location_counter=0; int literal_no1=1; int literal_no2=1; int L=0; //To keep track of Literals int C=0; //To keep track of Constants int cnt=0; int s=0; //For symbols FILE *fp2,*fp3; //----------------------------------------------------------------------------// //Structure for Mnemonic Table typedef struct mnemonic_table mnemonic_table; struct mnemonic_table { int mno; char mcode[10]; //Assembly mnemonic int ocode; //Instruction Opcode int length; //Default 1 char type[5]; //AD,DL,IS };

mnemonic_table mtable[15]; //----------------------------------------------------------------------------// //Structure for Symbol Table typedef struct symbol symbol; struct symbol { int sno; //Symbol No char sname[10]; //Symbol int saddr; //Symbol Addresss int slength; }; symbol sym_table[10]; //----------------------------------------------------------------------------// void initialize_mtable(); int find(char []); void label_initialize(); void pass1(); void labels(); //----------------------------------------------------------------------------// main(void) { FILE *fp1,*fp2; char temp[30]; fp1=fopen("C:\input.txt","r"); if(!fp1) printf("\t\t FILE NOT OPENED !!!\n"); printf("\n------------------------INPUT-------------------------------\n "); while(!feof(fp1)) { fgets(temp,30,fp1); printf("%s",temp); } printf("-------------------------------------------------------------\n" ); fp2=fopen("C:\icode.txt","w"); fputs("LC\tIC\tOP\tOPE1\tIC->OPE2\n\n",fp2); fp3=fopen("C:\literal.txt","w"); fputs("No\tLiteral\tAddress\n\n",fp3); fcloseall(); labels(); printf("\nInput Code--->input.txt\n"); printf("\nIntermediate Code--->icode.txt\n"); printf("\nSymbol Table--->symbol.txt\n"); printf("\nLiteral Table--->literal.txt\n");

getch(); } //----------------------------------------------------------------------------// void initialize_mtable() { int i; int j=1; //------------------------------------------------------------------------// //Assembler Directives strcpy(mtable[0].mcode,"START"); strcpy(mtable[1].mcode,"END"); strcpy(mtable[2].mcode,"ORIGIN"); strcpy(mtable[3].mcode,"LTORG"); strcpy(mtable[4].mcode,"EQU"); for(i=0;i
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF