You are on page 1of 55

WWW.VIDYARTHIPLUS.

COM

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM-622501

PUDUKKOTTAI DISTRICT

LAB MANUAL

Academic Year 2012-2013 (Odd)

Subject : System Software Lab


Dept : Computer Science and Engineering
Year/Sem : III/V
Handled by : C.Vennila

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

SUDHARSAN ENGINEERING COLLEGE


Sathiyamangalam, Pudhukottai
Department Of Computer Science and Engineering

LIST OF EXPERIMENTS

Dept/Year/ Sem : CSE/III / V Subject Name: System Software Lab

List of Experiments
1. Implementation of Token Separation.
2. Implementation of Symbol table Manipulation
3. Implementation of pass one of Two pass Assembler
4. Implementation of pass Two of Two pass Assembler
5. Implementation of one pass Assembler
6. Simulation of absolute loader
7. Simulation of Linking Loader
8. Implementation of Inter-process Communication
9. Implementation of Macro Substitution
10. Design of Editor

List of Equipments and Components for a batch of 30 Students (1 per batch)


1. SOFTWARE REQUIRED - TURBO C VERSION 3 or GCC VERSION 3.3.4

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

TOKEN SEPARATION
AIM:
To write a program to implement the token separation operation

AlGORITHM:
Step 1: Start the program.
Step 2: Store the possible keywords in an array key[][] and their corresponding byte value
in b[].
Step 3: Declare all the variables.
Step 4: Declare the file pointer fp for file operation.
Step 5: Open a file sym.c in write mode.
Step 6: Enter valid data into sym.c file until “#” symbol encountered. Then close the file.
Step 7: Open d.c file in read mode.Read the character one by one.
Step 8: If not End of file using switch case check for special symbols.Print the special
symbol.
Step 9: Check whether the string is alphabet or alphanumeric using isalpha() and
isalnum() functions.
Step 10: If the string is alphabet assign it to variable “a” and compare with keywords in
array using strcmp() function.
Step 11: If string is keyword print the keyword and its corresponding byte value and copy
the string to variable ”data” using strcpy() .
Step 12: Else copy to variable “sym”.
Step 13: Check for the character is constant value using isdigti() function and copy the
constant in the variable “val” using strcpy().
Step 14: Print all the datatype, identifier and constant value.
Step 15: Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
char key[5][10]={"int","float","char","double"};
int b[5]={2,1,4,8};
int main()
{
int byte;
int label;
int i,j,n,k=0;
char data[10],sym[10],val[10];
char a[20];

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

char str;
FILE *fp;
clrscr();
fp=fopen("sym.c","w");
printf("\n enter a valid declarations:");
while((str=getchar())!='#')
{
fputc(str,fp);
}
fclose(fp);
fp=fopen("d.c","r");
printf("\n______________________________________");
printf("\t\t SYMBOL TABLE\n");
printf("\n________________________________________");
printf("\ndata-type\tidentifier\tvalue\tbytes-occupied\n");
while((str=fgetc(fp))!=EOF)
{
i=0;
label=0;
switch(str)
{
case ';':
printf("\n\t%d\t%c\t a special symbol",n++,str);
break;

default:
if(isalpha(str))
{
do{
a[i]=str;
i++;
str=fgetc(fp);
}while(isalpha(str)||isalnum(str));
a[i]='\0';
fseek(fp,-1,1);
for(i=0;i<5;i++)
{
if(strcmp(a,key[i])==0)
{
// printf("\n\t%d\t%s\t a keyword",n++,a);
byte=b[i];
strcpy(data,a);
label=1;
goto aa;
}
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

if(label==0)
{
strcpy(sym,a);
}
}

else if(str=='=')
{
str=fgetc(fp);
if(str=='\'')
str=fgetc(fp);
goto aa;
}
else
aa:

if(isdigit(str)||isalpha(str))
{
do{
a[i]=str;
i++;
str=fgetc(fp);
}while(isdigit(str)||str=='.'||isalpha(str));
a[i]='\0';
fseek(fp,-1,1);
strcpy(val,a);
}
}
}
fclose(fp);
getch();
}

OUTPUT:

enter a valid data:


void main()
{
int a=5;
}
#

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

TOKEN SEPARATION

token no. token name token-type

1 void a keyword
2 main a keyword
3 ( a special symbol
4 ) a special symbol
5 { a special symbol
6 int a keyword
7 a an identifier
8 = an operator
9 5 a constant
10 ; a special symbol
11 } a special symbol

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

SYMBOL TABLE

AIM:
To write a program to implement the Symbol table operation

AlGORITHM:

Step 1: Start the program.


Step 2: Store the possible keywords in an array key [][] and their corresponding byte
value in b[].
Step 3: Declare all the variables.
Step 4: Declare the file pointer fp for file operations.
Step 5: Open d.c file in write mode and enter the valid data with ‘#’ symbol at the end of
file.Then close the file.
Step 6:Open d.c in read mode.Read the character one by one.
Step 7: If not end of file, using switch case display the character is special symbol or an
operator.
Step 8: Check whether the string is alphabet or alphanumeric using isalpha() and
isalnum() functions respectively.
Step 9: If the string is alphabet assign it to variable “a” and compare with the keywords in
array using strcmp() function.
Step 10: Then print keyword and its corresponding byte value and copy string to variable
“data” using strcpy().
Step 11: Else copy to variable “sym” .
Step 12: Check the string is alphabet or digit using isdigit() and isalpha() functions.
Step 13: If the string is digit then print the string is constant.
Step 14: Take fp to the assigned position.
Step 15: Close fp.
Step 16: Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
char key[5][10]={"int","float","char","double"};
int b[5]={2,4,1,8};
int main()
{ int byte;
int label;
int i,j,n,k=0;
char data[10],sym[10],val[10];
char a[20];
WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

char str;
FILE *fp;
clrscr();
fp=fopen("sym.c","w");
printf("\n enter a valid declarations:");
while((str=getchar())!='#')
{
fputc(str,fp);
}
fclose(fp);
fp=fopen("sym.c","r");
printf("\n______________________________________");
printf("\n\t\t SYMBOL TABLE\n");
printf("\n________________________________________");
printf("\ndata-type\tidentifier\tvalue\tbytes-occupied\n");
while((str=fgetc(fp))!=EOF)
{
i=0;
label=0;
switch(str)
{
case ';':
printf("\n%s\t\t%s\t\t%s\t\t%d",data,sym,val,byte);
break;

default:
if(isalpha(str))
{
do{
a[i]=str;
i++;
str=fgetc(fp);
}while(isalpha(str)||isalnum(str));
a[i]='\0';
fseek(fp,-1,1);
for(i=0;i<5;i++)
{
if(strcmp(a,key[i])==0)
{
// printf("\n\t%d\t%s\t a keyword",n++,a);
byte=b[i];
strcpy(data,a);
label=1;
goto aa;
}
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

if(label==0)
{
strcpy(sym,a);
}
}

else if(str=='=')
{
str=fgetc(fp);
if(str=='\'')
str=fgetc(fp);
goto aa;
}
else
aa:
if(isdigit(str)||isalpha(str))
{
do{
a[i]=str;
i++;
str=fgetc(fp);
}while(isdigit(str)||str=='.'||isalpha(str));
a[i]='\0';
fseek(fp,-1,1);
strcpy(val,a);
}
}
}
fclose(fp);
getch();
}

OUTPUT:
enter a valid declarations:int a=5;
float f=3.4;
double d=6.7;
char c='f';
#

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

______________________________________
SYMBOL TABLE

________________________________________
data-type identifier value bytes-occupied

int a 5 2
float f 3.4 4
double d 6.7 8
char c f 1

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

FIRST PASS OF TWO PASS ASSEMBLER

AIM:
To write a c program to perform first pass of two pass assembler.
ALGORITHM:
 Start the program.
 Get the assembly language program and the optab.
 Display the symbol names along with its address in the symbol table.
 Display the assembly language program along with its address in the intermediate
file.
 Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct instruction
{
char symbol[10];
char opcode[10];
}in;
struct opcode
{
char opcode[10];
char val[10];
}op;
void main()
{
FILE *fin,*flab,*fsym,*fint;
int locctr;
int length;
int val;
char val1[10];
int len;
char operand[10];
int startadd;
clrscr();
fin=fopen("inp.c","r");
flab=fopen("optab.c","r");
fsym=fopen("symb.c","w");
fint=fopen("inter.c","w");
fscanf(fin,"%s%s",in.symbol,in.opcode);
while(!feof(fin))
{
WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

if(strcmp(in.symbol,"-")!=0&&strcmp(in.opcode,"START")!=0)
{
fprintf(fsym,"%s\t%d\n",in.symbol,locctr);
}
if(strcmp(in.opcode,"START")==0)
{
printf("START\n");
fscanf(fin,"%d",&val);
printf("val=%d\n",val);
locctr=val;
startadd=val;
fscanf(fin,"%s%s",in.symbol,in.opcode);
if(strcmp(in.symbol,"-")!=0)
{
fprintf(fsym,"%s\t%d\n",in.symbol,locctr);
}
}
rewind(flab);
while(!feof(flab))
{
fscanf(flab,"%s%s",op.opcode,op.val);
if(strcmp(op.opcode,in.opcode)==0)
{
printf("instruction\n");
fscanf(fin,"%s",operand);
fprintf(fint,"%d\t%s\t%s\t%s\n",locctr,in.symbol,in.opcode,operand);
locctr=locctr+3;
}
}
if(strcmp(in.opcode,"WORD")==0);
{
printf("WORD\n");
fscanf(fin,"%d",&val);
fprintf(fint,"%d\t%s\t%s\t%d\n",locctr,in.symbol,in.opcode,val);
locctr=locctr+3;
}
else if(strcmp(in.opcode,"BYTE")==0)
{
printf("BYTE\n");
fscanf(fin,"%s",val1);
fprintf(fint,"%d\t%s\t%s\t%s\n",locctr,in.symbol,in.opcode,val1);
if(val1[0]=='c')
{
len=strlen(val1);
locctr=locctr+len-1;
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

else
{
locctr+=1;
}
}
else if(strcmp(in.opcode,"RESW")==0)
{
printf("RESW\n");
fscanf(fin,"%d",&val);
fprintf(fint,"%d\t%s\t%s\t%d\n",locctr,in.symbol,in.opcode,val);
locctr=locctr+3*val;
}
else if(strcmp(in.opcode,"RESB")==0)
{
printf("RESB\n");
fscanf(fin,"%d",&val);
fprintf(fint,"%d\t%s\t%s\t%d\n",locctr,in.symbol,in.opcode,val);
locctr=locctr+val;
}
else if(strcmp(in.opcode,"END")==0)
{
printf("END\n");
fscanf(fin,"%s",operand);
fprintf(fint,"%d\t%s\t%s\t%s\n",locctr,in.symbol,in.opcode,operand);
length=locctr+startadd;
printf("length=%d",length);
}
fscanf(fin,"%s%s\n",in.symbol,in.opcode);
}
fclose(fin);
fclose(fsym);
fclose(fint);
fclose(flab);
getch();
}

INPUT:
COPY START 1000
FIRST LDA ALPHA
ADD ONE
_ SUB INCR
_ STA BETA
_ BYTE X'F1'
ALPHA RESW 1

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

ONE RESW 1
INCR RESW 1
BETA RESW 1
_ END FIRST

OPTAB:
LDA 00
ADD 18
SUB 0C
STA 1C

OUTPUT:

SYMBOL TABLE:
1000 START
1003 LDA
1006 ADD
1009 SUB
1012 STA
1013 BYTE

INTERMADIATE FILE:

1000 FIRST LDA ALPHA


1003 _ ADD INCR
1006 _ SUB ONE
1009 _ STA BETA
1012 ONE BYTE X’F1’
1013 ALPHA RESW 1
1016 INCR RESW 1
1019 BETA RESW 1
1022 _ END FIRST

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

PASS TWO OF TWO PASS ASSEMBLER

AIM:
To write a c program to perform pass two of two pass assembler.

ALGORITHM:
 Start the program.
 Get the intermediate file from pass one of the two pass assembler.
 Display the opcode values along with its address.
 Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct instruction
{
int addr;
char symbol[10];
char opcode[10];
}in;
struct opcode
{
char opcode[10];
char val[10];
}op;
struct symbol
{
char label[10];
int addr;
}s;
void main()
{
FILE*ftab,*fint,*fsym,*fout;
char val1[10],temp1[10];
int val,address;
clrscr();
fint=fopen("inter.c","r");
fout=fopen("output.c","w");
fscanf(fint,"%d%s%s",&in.addr,in.symbol,in.opcode);
while(!feof(fint))
{
if(strcmp(in.opcode,"WORD")==0)
{
fscanf(fint,"%d",val);
fprintf(fout,"%d\t%d\n",in.addr,val);
WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

}
else if(strcmp(in.opcode,"BYTE")==0)
{
fscanf(fint,"%s",val1);
fprintf(fout,"%d\t%s\n",in.addr,val1);
}
else if(strcmp(in.opcode,"RESSW")==0)
{
fscanf(fint,"%d",&val);
}
else if(strcmp(in.opcode,"RESB")==0)
{
fscanf(fint,"%d",&val);
}
else if(strcmp(in.opcode,"END")==0)
{
fscanf(fint,"%s",val1);
}
else
{
fscanf(fint,"%s",val1);
ftab=fopen("optab.c","r");
fscanf(ftab,"%s%s",op.opcode,op.val);
while(!feof(ftab))
{
if(strcmp(in.opcode,op.opcode)==0)
{
strcpy(temp1,op.val);
}
fscanf(ftab,"%s%s",op.opcode,op.val);
}
fclose(ftab);
fsym=fopen("symb.c","r");
fscanf(fsym,"%s%d",s.label,&s.addr);
while(!feof(fsym))
{
if(strcmp(val1,s.label)==0)
{
address=s.addr;
}
fscanf(fsym,"%s%d",s.label,&s.addr);
}
fclose(fsym);
fprintf(fout,"%d\t%s\n",in.addr,temp1,address);
}
fscanf(fint,"%d%s%s",&in.addr,in.symbol,in.opcode);

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

}
printf("OBJECT PROGRAM IS STORED IN OUTPUT.C\n");
getch();
}

INPUT:
INTERMADIATE FILE:

1000 FIRST LDA ALPHA


1003 _ ADD INCR
1006 _ SUB ONE
1009 _ STA BETA
1012 ONE BYTE X’F1’
1013 ALPHA RESW 1
1016 INCR RESW 1
1019 BETA RESW 1
1022 _ END FIRST

OUTPUT:
1000 00
1003 18
1006 1C
1009 1C
1012 X’F1’
1013 1C
1016 1C
1019 1C

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

ONE PASS ASSEMBLER

AIM:

To write a C program to perform one pass assembler.

ALGORITHM:

 Start the program.


 Enter the assembly language instructions.
 Display the assembler directives with its equivalent object code.
 Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *f1,*f2;
char ch,str[30],str1[10],str2[30],cstr[15];
int i,j,num,q,r;
clrscr();
printf("Enter your assembly instructions\n");
f1=fopen("asin","w");
while(1)
{
ch=getchar();
if(ch=='*')
break;
fputc(ch,f1);
}
fclose(f1);
f1=fopen("asin","r");
f2=fopen("asout","w");
while(1)
{
fgets(str,25,f1);
strncpy(str1,str,3);
str1[3]='\0';
j=0;
for(i=3;i<strlen(str);i++)

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

{
str2[j]=str[i];
j++;
}
str2[j]='\0';
if((strcmp(str1,"lda"))==0)
{
fputs("3a\t",f2);
fputs(str2,f2);
}
else if((strcmp(str1,"mov"))==0)
{
fputs("47\n",f2);
}
else if((strcmp(str1,"add"))==0)
{
fputs("80\n",f2);
}
else if((strcmp(str1,"sub"))==0)
{
fputs("90\n",f2);
}
else if((strcmp(str1,"hlt"))==0)
{
fputs("76\n",f2);
break;
}
else if((strcmp(str1,"sta"))==0)
{
fputs("32\t",f2);
num=atoi(str2);
q=num/100;
r=num%100;
if(r==0)
fputs("00\t",f2);
else
fputs(itoa(r,cstr,10),f2);
fputs("\t",f2);
fputs(itoa(q,cstr,10),f2);
fputs("\n",f2);
}
else
{
fputs("error\n",f2);
}
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

fclose(f1);
fclose(f2);
f2=fopen("asout","r");
printf("\nTHE OBJECT CODE CONTENTS\n");
ch=fgetc(f2);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(f2);
}
fclose(f2);
getch();
}

Input and Output:

Enter your assembly instructions


lda 500
sub z
sta 9988
hlt
*

THE OBJECT CODE CONTENTS


3a 500
90
32 88 99
76

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

DIRECT LINKING LOADER

AIM:
To write a c program to perform one pass of direct linking loader.
ALGORITHM:
 Start the program.
 Get an assembly language programs as input.
 Display the symbol names in the above programs along with its program
name,length and address in the external symblol table.
 Stop the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct instruction
{
char iden[10];
char name[10];
}in;
void main()
{
FILE *fin,*fesym;
int v1,v2,val,*cslth,val1,val2,c,d;
char *id1,*id2,name2[10],v[10];
int csaddr=0,progaddr,temp1;
clrscr();
fin=fopen("loadinp.c","r");
fesym=fopen("extsymtab.c","w");
printf("\t\t\tCreation of external symboltable\n");
printf("Enter the relocation adress");
scanf("%d",&progaddr);
csaddr=progaddr;
printf("Starting address:%d",progaddr);
printf("\nFirst control section address:%d",csaddr);
fprintf(fesym,"_____External symbol table___");
fscanf(fin,"%s%s",in.iden,in.name);
while(!feof(fin))
{
if(strcmp(in.iden,"H")==0)
{
int t;
fscanf(fin,"%s%s",id1,val);
fprintf(fesym,"\nControl section name\tsymbolname\taddress\tlength");
fprintf(fesym,"\n%s\t\t\t\t\t%d\t\t%s",in.name,csaddr,val);
cslth=val;
}
WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

else if(strcmp(in.iden,"H1")==0)
{
int t;
fscanf(fin,"%s%s",id1,val1);
fprintf(fesym,"\n%s\t\t\t\t\t%d\t\t%s",in.name,c,csaddr,val1);
cslth=val1;
t=atoi(val1);
csaddr=t+csaddr;
printf("\nLast control section address:%d",csaddr);
}
else if(strcmp(in.iden,"H2")==0)
{
int t;
fscanf(fin,"%s%s",id1,val2);
fprintf(fesym,"\n%s\t\t\t\t\t%d\t%s",in.name,c,csaddr,val2);
cslth=val2;
/*t=atoi(val2);
csaddr=t+csaddr;
printf("%d",csaddr);*/
}
else if(strcmp(in.iden,"D")==0)
{
int n,m,temp,temp1;
fscanf(fin,"%s%s%s",id1,name2,id2);
n=atoi(id1);
m=atoi(id2);
temp=csaddr+n;
temp1=csaddr+m;
fprintf(fesym,"\n\t\t\t%s\t\t%d\n\t\t\t%s\t\t%d\n",in.name,temp,name2,temp1);
c=atoi(cslth);
csaddr=c+csaddr;
}
fscanf(fin,"%s%s",in.iden,in.name);
}
getch();}
INPUT:
H PROGA 0000 0063
D LISTA 0040 ENDA 0054
R LISTB ENDB LISTC ENDC
T 00020 0A
M 00010 05
M 00000 05
E 00000
H1 PROGB 0000 0077
D LISTB 0060 ENDB 0070
R LISTA ENDA LISTC ENDC

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

T 00030 0C
M 00020 05
M 00050 05
E 00000
H2 PROGC 0000 0083
D LISTC 0075 ENDC 0090
R LISTA ENDA LISTB ENDB
T 00040 06
M 00054 05
M 00060 05
E 00000
Output:
_____External symbol table___
Control section name symbolname address length
PROGA 2000 0063
LISTA 2040
ENDA 2054

PROGB 2063 0077


LISTB 2200
ENDB 2210

PROGC 2140 0083


LISTC 2292
ENDC 2307

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

ABSOLUTE LOADER

AIM:
To write a c program to perform absolute loader.
ALGORITHM:
 Start the program.
 Get the header record,text record and end record.
 Display the program name,starting address,program length and the text address.
 Stop the program.

PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *myfile;
int i=0,f=0,f1=0,j,k;
char ch,fn[30],stadd[15],textrec[80];
clrscr();
myfile=fopen("in.txt","r");
if(myfile == NULL)
{
puts("Cannot open the file");
exit(0);
}
while((!feof(myfile)) && f1==0)
{
while(f1==0)
{
ch = fgetc(myfile);
if((ch=='H' || ch=='h' ) && f==0)
f=1;
if(ch=='-')
{
f1=1;
break;
}
if(ch != 'H' && f==1 && f1==0)
{
fn[i]=ch;
i++;
fn[i]='\0';
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

}
if(f1==1)
for(j=0;j<=12;j++)
stadd[j]=(ch=fgetc(myfile));
stadd[j]='\0';
while(!feof(myfile))
{
ch=fgetc(myfile);
if(ch=='T')
for(k=1;k<=80;k++)
textrec[k]=(ch=fgetc(myfile));
textrec[k]='\0';
}

printf("program name is %s \n",fn);

printf("\n starting address ");


for(i=0;i<=5;i++)
printf("%c",stadd[i]);

printf("\n Length of the program ");


for(i=7;i<=12;i++)
printf("%c",stadd[i]);

printf("\n \n text address %s \n",textrec);


for(i=1;i<=80;i++)
{
if((i%7)!=0)
printf("%c",textrec[i]);
else
printf("\n");
}
getch();
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

INPUT:
IN.TXT
HCOPY-001000-00107A
T001000-141033-482039-001036-281030-301015-482061-00102D
001000

OUTPUT:
program name is COPY

starting address 1000


LENGTH OFPROGRAM 00107A

Text address
001000
141033
482039
001036
281030
301015

482061
00102D

001000

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

MACROPROCESSOR

AIM:
To write a c program to perform macro substitution.
ALGORITHM:
 Start the program.
 Get the assembly language program as input.
 When the macro name occurs, substitute the contents of the macro.
 Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct ins
{
char symbol[10];
char opcode[10];
char val[10];
}i;
void main()
{
FILE *fp,*fin;
char temp[10];
char name[10][10];
int j,t,i1,totmac=0;
clrscr();
fin=fopen("inmac.c","r");
fscanf(fin,"%s%s%s",i.symbol,i.opcode,i.val);
while(!feof(fin))
{
if(strcmp(i.opcode,"MACRO")==0)
{
totmac+=1;
strcpy(name[totmac],i.symbol);
fp=fopen(i.symbol,"w");
while(strcmp(i.opcode,"MEND")!=0)
{
fprintf(fp,"%s\t%s\t%s\n",i.symbol,i.opcode,i.val);
fscanf(fin,"%s%s%s",i.symbol,i.opcode,i.val);
}
fclose(fp);
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

else
{
t=0,j=0;
for(i1=1;i1<=totmac;i1++)
{
if(strcmp(i.opcode,name[i1])==0)
{
t=1;
fp=fopen(i.opcode,"r");
printf(".");
fscanf(fp,"%s",temp);
while(!feof(fp))
{
j++;
if(j<3)
printf("%s\t",temp);
if(j==3)
{
printf("%s\n",temp);
j=0;
}
fscanf(fp,"%s",temp);
}
}
}
if(t==0)
{
printf("%s\t%s\t%s\n",i.symbol,i.opcode,i.val);
}
}
fscanf(fin,"%s%s%s",i.symbol,i.opcode,i.val);
}
getch();
}
INPUT :

INMAC.C

COPY START 1000


A1 MACRO _
_ LDA ALPHA
_ SUB ONE
_ STA BETA
_ MEND _
FIRST CLEAR A
_ A1 _

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

ALPHA RESW 1
INCR RESW 1
ONE WORD 1
BETAR RESW 1
_ END FIRST

OUTPUT:

COPY START 1000


FIRST CLEAR A
.A1 MACRO _
_ LDA ALPHA
_ SUB ONE
_ STA BETA
ALPHA RESW 1
INCR RESW 1
ONE WORD 1
BETAR RESW 1
_ END FIRST

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

TEXT EDITOR

AIM:
To write a c program to create a text editor.

ALGORITHM:
 Start the program.
 List the menu.
 Get the choice,ch.
 If ch is 1,create a new file.
 If ch is 2,open the required file.
 If ch is 3,get the file name to be edited,enter the new text until * is entered.
 If ch is 4,exit.
 Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
//#include<string.h>
//#include<bios.h>
void main()
{
int ch;
clrscr();
printf("\t\tEditor\n");
printf("\t\t\t-------\n");
while(1)
{
printf("\nMenu details\n");
printf("------------\n");
printf("1.New file creation\n");
printf("2.Open file\n");
printf("3.Edit\n");
printf("4.Exit\n");
printf("Enter the chioce\n");
scanf("%d",&ch);
switch(ch)
{
case 1:

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

createfile();
break;
case 2:
openfile();
break;
case 3:
editfile();
break;
case 4:
exit(0);
break;
}
}
getch();
}
createfile()
{
char c,nam[20];
FILE *fp;
printf("Enter the name of the file you want to create\n");
scanf("%s",nam);
fp=fopen(nam,"w");
c=getchar();
while(c!='*')
{
fputc(c,fp);
c=getchar();
}
fclose(fp);
}
openfile()
{
char c,nam[20];
FILE *fp;
printf("Enter the name of the file you want to open\n");
scanf("%s",nam);
fp=fopen(nam,"r");
do
{
c=fgetc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
}
editfile()

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

{
char c,nam[20];
FILE *fp;
printf("Enter the contents of the file you want to append\n");
scanf("%s",nam);
fp=fopen(nam,"a");
c=getchar();
while(c!='*')
{
fputc(c,fp);
c=getchar();
}
fclose(fp);
}
INPUT AND OUTPUT:
Editor
------------

menu details
----------------
1.new file creation
2.open file
3.edit
4.exit
enter the choice
1
enter the name of the file you want to create
ss.txt
soundarya*

menu details
----------------
1.new file creation
2.open file
3.edit
4.exit
enter the choice
2
Enter the name of the file you want to open
ss.txt

soundarya
Menu details
------------
1.New file creation
2.Open file

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

3.Edit
4.Exit
Enter the chioce
3
Enter the contents of the file you want to append
ss.txt
vijayakumar*
Menu details
------------
1.New file creation
2.Open file
3.Edit
4.Exit
Enter the chioce
2
Enter the name of the file you want to open
ss.txt

soundarya
vijayakumar
Menu details
------------
1.New file creation
2.Open file
3.Edit
4.Exit
Enter the chioce
4

RESULT:
Thus the program was implemented and verified.

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

Input

H^PROGA^000000^000054^
D^LISTA^000040^ENDA^000054^
R^LISTB^
T^000020^03^032010^
T^000023^04^77100004^
M^000024^05^+^LISTB^
E^000020^

H^PROGB^000000^000070^
D^LISTB^000060^ENDB^000070^
R^LISTA^
T^000036^04^03100000^
T^00003A^03^04^772027^
M^000037^05^+^LISTA^
E^000036^

Program

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
int htod(char *);
void main()
{
int pa=5000,cs,cs1,x=0,y=0,l=0,t;
FILE *f1,*f2;
char p[20],c,str[10],st[20][20];
clrscr();
itoa(pa,p,10);
pa=htod(p);
cs=pa;
cs1=cs;
f1=fopen("INT1.c","r");
f2=fopen("out1.c","w");
printf("\t\tESTAB\n");
fprintf(f2,"\t\tESTAB\n");
printf("\tCONTROL SECTION SYMBOL NAME ADDRESS LENGTH\n");
fprintf(f2,"\tCONTROL SECTION SYMBOL NAME ADDRESS LENGTH\n");
while((c=getc(f1))!=EOF)

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

{
if(c=='H')
{
y=0;
while((c=getc(f1))!='\n')
{
if(c!='^')
{
str[x]=c;
x++;
}
else
{
str[x]='\0';
strcpy(st[y],str);
if(y==1)
{
printf("%s\t\t",st[y]);
fprintf(f2,"%s\t\t",st[y]);
}
else if(y==3)
{
printf("\t\t%x\t%s\t\n",cs1,st[y]);
fprintf(f2,"\t\t\t%x\t%s\t\n",cs1,st[y]);
t=htod(st[y]);
}
x=0;
y++;
}
}
}
else if(c=='D')
{
y=0;
while((c=getc(f1))!='\n')
{
if(c!='^')
{
str[x]=c;
x++;
}
else
{
str[x]='\0';
strcpy(st[y],str);
if(y!=0)

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

{
if(y%2==0)
{
l=htod(st[y]);
l=l+cs1;
printf("\t\t\t\t%x",l);
fprintf(f2,"\t\t\t\t%x",l);
}
else
{
printf("\t%s",st[y]);
fprintf(f2,"\t%s",st[y]);
}
}
if(y%2==0)
{
printf("\n\n\n\n");
fprintf(f2,"\n\n\n\n");
}
x=0;
y++;
}
}
}
else if(c=='E')
{
cs1=cs1+t;
}
}
getch();
}

int htod(char *s)


{
char temp[10];
int i,j=0,sum=0,k;
int n=strlen(s);
n=n-1;
for(i=n;i>=0;i--)
{
if(s[i]=='A')
strcpy(temp,"10");
if(s[i]=='B')
strcpy(temp,"11");
if(s[i]=='C')
strcpy(temp,"12");

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

if(s[i]=='D')
strcpy(temp,"13");
if(s[i]=='E')
strcpy(temp,"14");
if(s[i]=='F')
strcpy(temp,"15");
else
{
temp[0]=s[i];
temp[1]='\0';
}
k=atoi(temp)*pow(16,j);
sum=sum+k;
j+=1;
}
return sum;
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

Reloc:

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

void convert(char h[12]);

char bitmask[12];

char bit[12]={0};

void main()

char add[6],length[10],input[10],binary[12],relocbit,ch,pn[5];

int start,inp,len,i,address,opcode,addr,actualadd,tlen;

int flag=1;
FILE *fp1,*fp2;
clrscr();

printf("\n\n Enter the actual starting address : ");

scanf("%x",&start);

fp1=fopen("RLIN.DAT","r");

fp2=fopen("RLOUT.DAT","w");

fscanf(fp1,"%s",input);

fprintf(fp2," -------\n");

fprintf(fp2," ADDRESS\tCONTENT\n");

fprintf(fp2," ---------\n");

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

while(strcmp(input,"E")!=0)

if(strcmp(input,"H")==0)

fscanf(fp1,"%s",pn);

fscanf(fp1,"%x",add);

fscanf(fp1,"%x",length);

fscanf(fp1,"%s",input);

if(strcmp(input,"T")==0)

fscanf(fp1,"%x",&address);

fscanf(fp1,"%x",&tlen);

fscanf(fp1,"%s",bitmask);

if(flag==1)
{
address = 0;
flag=0;
}
address+=start;

convert(bitmask);

len=strlen(bit);

if(len>=11)

len=10;

for(i=0;i<len;i++)

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

fscanf(fp1,"%x",&opcode);

fscanf(fp1,"%x",&addr);

relocbit=bit[i];

if(relocbit=='0')

actualadd=addr;

else

actualadd=addr+start;

fprintf(fp2,"\n %x\t\t%x %x\n",address,opcode,actualadd);

address+=3;

fscanf(fp1,"%s",input);

fprintf(fp2,"--------\n");

fcloseall();

printf("\n\n The contents of output file (RLOUT.DAT):\n\n");

fp2=fopen("RLOUT.DAT","r");

ch=fgetc(fp2);

while(ch!=EOF)

printf("%c",ch);

ch=fgetc(fp2);

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

fclose(fp2);

getch();

void convert(char h[12])

int i,l;

strcpy(bit,"");

l=strlen(h);

for(i=0;i<l;i++)

switch(h[i])

case '0':

strcat(bit,"0");

break;

case '1':

strcat(bit,"1");

break;

case '2':

strcat(bit,"10");

break;

case '3':

strcat(bit,"11");

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

break;

case '4':

strcat(bit,"100");

break;

case '5':

strcat(bit,"101");

break;

case '6':

strcat(bit,"110");

break;

case '7':

strcat(bit,"111");

break;

case '8':

strcat(bit,"1000");

break;

case '9':

strcat(bit,"1001");

break;

case 'A':

strcat(bit,"1010");

break;

case 'B':

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

strcat(bit,"1011");

break;

case 'C':

strcat(bit,"1100");

break;

case 'D':

strcat(bit,"1101");

break;

case 'E':

strcat(bit,"1110");

break;

case 'F':

strcat(bit,"1111");

break;

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

Two Pass Macro


#include<stdio.h>
void main()
{
char a[10],b[10],c[10],a1[10],b1[10],c1[10];
FILE *fp1,*fp2,*fp3,*fp5,*fp4;
fp5=fopen("nametab.txt","w");
fp4=fopen("exp.txt","w");
fp1=fopen("in11.txt","r");
fp2=fopen("deftab.txt","w");
fscanf(fp1,"%s %s %s",a,b,c);
if(strcmp(b,"MACRO")==0)
{
fprintf(fp5,"%s\n",a);
}
fscanf(fp1,"%s %s %s",a,b,c);
while(strcmp(b,"MEND")!=0)
{
fprintf(fp2,"%s %s %s\n",a,b,c);
fscanf(fp1,"%s %s %s",a,b,c);
}
fprintf(fp2,"%s %s %s\n",a,b,c);
fclose(fp2);
fscanf(fp1,"%s %s %s",a,b,c);
while(!feof(fp1))
{
fscanf(fp1,"%s %s %s",a,b,c);
if(strcmp(b,"SUM")==0)
{
fp3=fopen("deftab.txt","r");
fscanf(fp3,"%s %s %s",a1,b1,c1);
//while(!feof(fp3))
while(strcmp(b1,"MEND")!=0)
{
fprintf(fp4,"%s %s %s\n",a1,b1,c1);
fscanf(fp3,"%s %s %s",a1,b1,c1);
}
}
fclose(fp3);

//printf("hi %s\n",b);
}}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

Input file

SUM MACRO a1
- LDA #5
- LDS a1
- ADDR A,S
- STA RES
- MEND -
- SUM 6
- SUM 8
- SUM 15
- SUM 14

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

IMPLEMENTATION OF A TWO PASS MACRO PROCESSOR


EX.NO:8
PROGRAM:
#include<stdio.h>
void main()
{
char a[10],b[10],c[10],a1[10],b1[10],c1[10];
FILE *fp1,*fp2,*fp3,*fp5,*fp4;
fp5=fopen("nametab.txt","w");
fp4=fopen("exp.txt","w");
fp1=fopen("in11.txt","r");
fp2=fopen("deftab.txt","w");
fscanf(fp1,"%s %s %s",a,b,c);
if(strcmp(b,"MACRO")==0)
{
fprintf(fp5,"%s\n",a);
}
fscanf(fp1,"%s %s %s",a,b,c);
while(strcmp(b,"MEND")!=0)
{
fprintf(fp2,"%s %s %s\n",a,b,c);
fscanf(fp1,"%s %s %s",a,b,c);
}
fprintf(fp2,"%s %s %s\n",a,b,c);
fclose(fp2);
fscanf(fp1,"%s %s %s",a,b,c);
while(!feof(fp1))
{
fscanf(fp1,"%s %s %s",a,b,c);
if(strcmp(b,"SUM")==0)
{
fp3=fopen("deftab.txt","r");
fscanf(fp3,"%s %s %s",a1,b1,c1);
//while(!feof(fp3))
while(strcmp(b1,"MEND")!=0)
{
fprintf(fp4,"%s %s %s\n",a1,b1,c1);
fscanf(fp3,"%s %s %s",a1,b1,c1);
}
}
fclose(fp3);

//printf("hi %s\n",b);
}}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

INPUT FILE:
C:\tc\bin\in11.txt
SUM MACRO a1
- LDA #5
- LDS a1
- ADDR A,S
- STA RES
- MEND -
- SUM 6
- SUM 8
- SUM 15
- SUM 14

OUTPUT:
nametab.txt:
SUM
exp.txt:-
- LDA #9
- LDS a1
- ADDR A,S
- STA RES
- LDA #5
- LDS a1
- ADDR A,S
- STA RES
- LDA #5
- LDS a1
- ADDR A,S
- STA RES
- LDA #5
- LDS a1
- ADDR A,S
- STA RES

deftab.txt:
- LDA #5
- LDS a1
- ADDR A,S
- STA RES
- MEND -

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

IMPLEMENTATION OF PASS TWO OF DIRECT LINKING LOADER


EX.NO:9
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct obj
{
char rec[20],sym[10],addr[20];
}ob;
struct estab
{
char sym[20];
int addr;
}
es;
void main()
{
FILE *f1,*f2;
int csaddr,maddr,cslth,addr;
clrscr();
f1=fopen("OBJ1.TXT","r");
f2=fopen("ESTAB1.TXT","r");
fscanf(f2,"%s%d",es.sym,&es.addr);
csaddr=es.addr;
printf("Memoryaddr Object code \n");
while(!feof(f1))
{
fscanf(f1,"%s%s%s",ob.rec,ob.sym,ob.addr);
cslth=atoi(ob.addr);
while(strcmp(ob.rec,"E")!=0)
{
int s;
fscanf(f1,"%s%s%s",ob.rec,ob.sym,ob.addr);
if(strcmp(ob.rec,"T")==0)
{
addr=csaddr+atoi(ob.sym);
s=atoi(ob.addr);

printf("%d\t %s\n",addr,ob.addr);
}
if(strcmp(ob.rec,"M")==0)
{
maddr=csaddr+atoi(ob.sym);

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

while(!feof(f2))
{
fscanf(f2,"%s%d",es.sym,&es.addr);
if(strcmp(ob.addr,es.sym)==0)
{
es.addr=es.addr+s;
printf("%d\t %d\n",maddr,es.addr);
break;
}
}
rewind(f2);
}
}
csaddr+ =cslth;
}
fcloseall();
getch();
}
INPUT FILE1:
C:\tc\bin\ESTAB1.TXT
PROGA 4000
LISTA 4040
PROGB 4063
LISTB 4093

INPUT FILE2:
C:\tc\bin\OBJ1.TXT
H PROGA 0063
D LISTA 0040
T 0054 0000
M 0054 LISTB
E 0003 NULL
H PROGB 0030
D LISTB 0030
T 0050 0000
M 0050 LISTA
E 0003 NULL

OUTPUT:
Memoryaddr Object code
4054 0000
4054 4093
4113 0000
4113 4040

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

IMPLEMENTATION OF A SIMPLE TEXT EDITOR


EX.NO:10
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct list
{
char text[100];
}l[100];
int i,n,x=0;
char s[100],s1[100];
void insert();
void search();
void display();
void main()
{
int ch;
clrscr();
do
{
printf("\t MENU\n");
printf("1.Insert \n 2.Search\n 3.Display\n 4.Exit");
printf("\n Enter the opinion:");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
search();
break;
case 3:
display();
break;
case 4:
exit(1);
}}
while(ch<=4);
getch();
}
void insert()
{
printf("\n Enter the no of words in the text:");

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

scanf("%d",&n);
printf("\n Enter the string:");
for(i=1;i<=n;i++)
{
scanf("%s",l[i].text);
}
}
void search()
{
printf("Enter the string to be searched:");
scanf("%s",s);
printf("Enter the string to be inserted:");
scanf("%s",s1);
for(i=1;i<=n;i++)
{
x=strcmp(l[i].text,s);
if(x==0)
{
strcpy(l[i].text,s1);
}
}
if(x!=0)
printf("String not found\n");
}
void display()
{
printf("The final string is:");
for(i=1;i<=n;i++)
{
printf("%s\t",l[i].text);
}
getch();
}

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

OUTPUT:
MENU
1. Insert
2. Search
3. Display
4. Exit
Enter the opinion: 1
Enter the no. of words in the text: 3
Enter the string: HAI HELLO BYE

MENU
1. Insert
2. Search
3. Display
4. Exit
Enter the opinion: 2
Enter the string to be searched: BYE
Enter the string to be inserted
THANKS

MENU
1. Insert
2. Search
3. Display
4. Exit
Enter the opinion: 2
Enter the string to be searched:BYE
Enter the string to be inserted:WELCOME
String not found

MENU
1. Insert
2. Search
3. Display
4. Exit
Enter the opinion: 3
The final string is: HAI HELLO THANKS

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

IMLEMENTATION OF A SINGLE PASS MACRO PROCESSOR


EX.NO:11
PROGRAM:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
int n,i,flag;
char ilab[20],iopd[20],oper[20],NAMTAB[20][20];
FILE *fp1,*fp2,*DEFTAB;
clrscr();
fp1=fopen("macin.dat","r");
fp2=fopen("macout.dat","w");
n=0;
rewind(fp1);
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
while(!feof(fp1))
{
if(strcmp(iopd,"MACRO")==0)
{
strcpy(NAMTAB[n],ilab);
DEFTAB=fopen(NAMTAB[n],"w");
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
while(strcmp(iopd,"MEND")!=0)
{
fprintf(DEFTAB,"%s %s %s\n",ilab,iopd,oper);
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
}
fclose(DEFTAB);
n++;
}
else
{
flag=0;
for(i=0;i<n;i++)
{
if(strcmp(iopd,NAMTAB[i])==0)
{
flag=1;
DEFTAB=fopen(NAMTAB[i],"r");
fscanf(DEFTAB,"%s%s%s",ilab,iopd,oper);
while(!feof(DEFTAB))
{

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

fprintf(fp2,"%s %s %s\n",ilab,iopd,oper);
fscanf(DEFTAB,"%s%s%s",ilab,iopd,oper);
}
break;
}
}
if(flag==0)
fprintf(fp2,"%s %s %s\n",ilab,iopd,oper);
}
fscanf(fp1,"%s%s%s",ilab,iopd,oper);
}
getch();
}

INPUTFILE:
C:\tc\bin\MACIN.DAT

M1 MACRO **
** LDA N1
** ADD N2
** STA N3
** MEND **
M2 MACRO **
** LDA N1
** SUB N2
** STA N4
** MEND **
M3 MACRO **
** LDA N1
** MUL N2
** STA N5
** MEND **
** START 1000
** M3 **
** M2 **
** M1 **
** END **

WWW.VIDYARTHIPLUS.COM BASARIYA
WWW.VIDYARTHIPLUS.COM

OUTPUT:

MACOUT.DAT

** START 1000
** LDA N1
** MUL N2
** STA N5
** LDA N1
** SUB N2
** STA N4
** LDA N1
** ADD N2
** STA N3
** END **

WWW.VIDYARTHIPLUS.COM BASARIYA

You might also like