Code:

#include <stdio.h>
#include <string.h>
int main()
{
FILE *infile;
FILE *outfile;
int j;
char a[20], out[20];
infile = fopen("LMC.dat", "r");
outfile = fopen("LMCdec.dat", "w");
while (NULL != fgets(a, 20, infile))
{
a[strlen(a)-1]='\0';
sscanf(a, "%s %d", out, &j);
if(0==strcmp(out, "LDA"))
{
fprintf(outfile, "%s\n%d\n", "5", j);
}
if(0==strcmp(out, "STO"))
{
fprintf(outfile, "%s\n%d\n", "3", j);
}
if(0==strcmp(out, "ADD"))
{
fprintf(outfile, "%s\n%d\n", "1", j);
}
if(0==strcmp(out, "SUB"))
{
fprintf(outfile, "%s\n%d\n", "2", j);
}
if(0==strcmp(out, "IN"))
{
fprintf(outfile, "%s\n", "9\n01", j);
}
if(0==strcmp(out, "OUT"))
{
fprintf(outfile, "%s\n", "9\n02", j);
}
if(0==strcmp(out, "BRZ"))
{
fprintf(outfile, "%s\n%d\n", "7", j);
}
if(0==strcmp(out, "BRP"))
{
fprintf(outfile, "%s\n%d\n", "8", j);
}
if(0==strcmp(out, "BR"))
{
fprintf(outfile, "%s\n%d\n", "6", j);
}
if(0==strcmp(out, "COB"))
{
fprintf(outfile, "%s\n%d\n", "0", j);
}
if(0==strcmp(out, "MUL"))
{
fprintf(outfile, "%s\n%d\n", "11", j);
}
if(0==strcmp(out, "EXP"))
{
fprintf(outfile, "%s\n%d\n", "12", j);
}
} /*end while*/
fclose(infile);
fclose(outfile);
return 0;
FILE *infile1;
FILE *outfile1;
char q[20], r[20];
int i;
i=0;
infile1 = fopen("LMCdec.dat", "r");
outfile1 = fopen("LMC.obj", "w");
while (NULL != fgets(q, 20, infile1))
{
q[strlen(q)-1]='\0';
sscanf(q, "%d", &i);
if(i >= 128)
{
r[0]='1';
i=i-128;
}
else r[0]='0';
if(i >= 64)
{
r[1]='1';
i=i-64;
}
else r[1]='0';
if(i >= 32)
{
r[2]='1';
i=i-32;
}
else r[2]='0';
if(i >= 16)
{
r[3]='1';
i=i-16;
}
else r[3]='0';
if(i >= 8)
{
r[4]='1';
i=i-8;
}
else r[4]='0';
if(i >= 4)
{
r[5]='1';
i=i-4;
}
else r[5]='0';
if(i >= 2)
{
r[6]='1';
i=i-2;
}
else r[6]='0';
if(i >= 1)
{
r[7]='1';
i=i-1;
}
else r[7]='0';
if(i >= 0)
{
r[8]='\0';
i=i-0;
}
else r[8]='0';
fprintf(outfile1, "%s\n", r);
} /*end while*/
fclose(infile1);
fclose(outfile1);
return 0;
} /*end main*/