Skip to content

Commit da9162a

Browse files
authored
Merge pull request #2 from Miniproject6984/main
15
2 parents 2e12d7d + 05be602 commit da9162a

File tree

15 files changed

+406
-178
lines changed

15 files changed

+406
-178
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"files.associations": {
3-
"string.h": "c"
3+
"string.h": "c",
4+
"random": "c"
45
},
56
"java.project.sourcePaths": [
67
"daa/11. Sort a given set of n integer elements using Quick Sort method and compute its time complexity. Run the program for"
Binary file not shown.
-144 Bytes
Binary file not shown.

cd/12. Write a program to perform loop unrolling./program.c

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,13 @@ void main()
66
unsigned int n;
77
int x;
88
char ch;
9-
// clrscr();
109
printf("\nEnter N\n");
1110
scanf("%u", &n);
12-
printf("\n1. Loop Roll\n2. Loop UnRoll\n");
13-
printf("\nEnter ur choice\n");
14-
scanf(" %c", &ch);
15-
switch (ch)
16-
{
17-
case '1':
18-
x = countbit1(n);
19-
printf("\nLoop Roll: Count of 1's : %d", x);
20-
break;
21-
case '2':
22-
x = countbit2(n);
23-
printf("\nLoop UnRoll: Count of 1's : %d", x);
24-
break;
25-
default:
26-
printf("\n Wrong Choice\n");
27-
}
28-
// getch();
11+
x = countbit(n);
12+
printf("\nAfter Loop UnRoll, Count of iterations : %d", x);
2913
}
30-
int countbit1(unsigned int n)
31-
{
32-
int bits = 0, i = 0;
33-
while (n != 0)
34-
{
35-
if (n & 1)
36-
bits++;
37-
n >>= 1;
38-
i++;
39-
}
40-
printf("\n no of iterations %d", i);
41-
return bits;
42-
}
43-
int countbit2(unsigned int n)
14+
15+
int countbit(unsigned int n)
4416
{
4517
int bits = 0, i = 0;
4618
while (n != 0)
@@ -56,6 +28,5 @@ int countbit2(unsigned int n)
5628
n >>= 4;
5729
i++;
5830
}
59-
printf("\n no of iterations %d", i);
6031
return bits;
6132
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
struct op
4+
{
5+
char l;
6+
char r[20];
7+
} op[10], pr[10];
8+
void main()
9+
{
10+
int a, i, k, j, n, z = 0, m, q;
11+
char *p, *l;
12+
char temp, t;
13+
char *temp;
14+
printf("Enter the no.of values");
15+
scanf("% d", &n);
16+
for (i = 0; i < n; i++)
17+
{
18+
printf("\tleft\t");
19+
op[i].l = getchar();
20+
printf("\tright\t");
21+
scanf("% s", op[i].r);
22+
}
23+
24+
printf("eliminate common sub expression\n");
25+
for (i = 0; i < z; i++)
26+
printf("% c\t =", pr[i].l);
27+
printf("% s\n", pr[i].r);
28+
// duplicate production elimination
29+
for (i = 0; i < z; i++)
30+
{
31+
for (j = i + 1; j < z; j++)
32+
{
33+
q = strcmp(pr[i].r, pr[j].r);
34+
if ((pr[i].l == pr[j].l) && !q)
35+
{
36+
pr[i].l =’\0’;
37+
strcpy(pr[i].r,’\0’);
38+
}
39+
}
40+
}
41+
printf("optimized code");
42+
for (i = 0; i < z; i++)
43+
{
44+
if (pr[i].l !=’\0’)
45+
{
46+
printf("% c =", pr[i].l);
47+
printf("% s\n", pr[i].r);
48+
}
49+
}
50+
getch();
51+
}
312 Bytes
Binary file not shown.

cd/13. Write a program to perform constant propagation./program.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
// write a program to perform constant propagation.
1+
// write a program to perform co propagation.
22

33

44
#include <stdio.h>
55
#include <string.h>
66
#include <ctype.h>
7-
void input();
8-
void output();
9-
void change(int p, char *res);
10-
void constant();
7+
void i();
8+
void o();
9+
void ch(int p, char *res);
10+
void co();
1111
struct expr
1212
{
1313
char op[2], op1[5], op2[5], res[5];
1414
int flag;
1515
} arr[10];
1616
int n;
17-
void main()
17+
int main()
1818
{
19-
clrscr();
20-
input();
21-
constant();
22-
output();
23-
getch();
24-
}
25-
void input()
19+
i();
20+
co();
21+
o();
22+
return 0;}
23+
void i()
2624
{
2725
int i;
28-
printf("\n\nEnter the maximum number of expressions : ");
26+
printf("\n\nEnter the maximum no. of expressions : ");
2927
scanf("%d", &n);
30-
printf("\nEnter the input : \n");
28+
printf("\nEnter the i : \n");
3129
for (i = 0; i < n; i++)
3230
{
3331
scanf("%s", arr[i].op);
@@ -37,7 +35,7 @@ void input()
3735
arr[i].flag = 0;
3836
}
3937
}
40-
void constant()
38+
void co()
4139
{
4240
int i;
4341
int op1, op2, res;
@@ -69,11 +67,11 @@ void constant()
6967
}
7068
sprintf(res1, "%d", res);
7169
arr[i].flag = 1; /*eliminate expr and replace any operand below that uses result of this expr */
72-
change(i, res1);
70+
ch(i, res1);
7371
}
7472
}
7573
}
76-
void output()
74+
void o()
7775
{
7876
int i = 0;
7977
printf("\nOptimized code is : ");
@@ -85,7 +83,7 @@ void output()
8583
}
8684
}
8785
}
88-
void change(int p, char *res)
86+
void ch(int p, char *res)
8987
{
9088
int i;
9189
for (i = p + 1; i < n; i++)
Binary file not shown.
Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
11
// Implement Intermediate code generation for simple expressions.
22

3-
#include<stdio.h>
4-
#include<string.h>
5-
char op[2],arg1[5],arg2[5],result[5];
6-
void main()
3+
#include <stdio.h>
4+
#include <string.h>
5+
char op[2], arg1[5], arg2[5], r[5];
6+
int main()
77
{
8-
FILE *fp1,*fp2;
9-
fp1=fopen("input.txt","r");
10-
fp2=fopen("output.txt","w");
11-
while(!feof(fp1))
8+
FILE *fp1, *fp2;
9+
fp1 = fopen("input.txt", "r");
10+
fp2 = fopen("output.txt", "w");
11+
while (!feof(fp1))
1212
{
1313

14-
fscanf(fp1,"%s%s%s%s",op,arg1,arg2,result);
15-
if(strcmp(op,"+")==0)
14+
fscanf(fp1, "%s%s%s%s", op, arg1, arg2, r);
15+
if (strcmp(op, "+") == 0)
1616
{
17-
fprintf(fp2,"\nMOV R0,%s",arg1);
18-
fprintf(fp2,"\nADD R0,%s",arg2);
19-
fprintf(fp2,"\nMOV %s,R0",result);
17+
fprintf(fp2, "\nMOV R0,%s", arg1);
18+
fprintf(fp2, "\nADD R0,%s", arg2);
19+
fprintf(fp2, "\nMOV %s,R0", r);
2020
}
21-
if(strcmp(op,"*")==0)
21+
if (strcmp(op, "*") == 0)
2222
{
23-
fprintf(fp2,"\nMOV R0,%s",arg1);
24-
fprintf(fp2,"\nMUL R0,%s",arg2);
25-
fprintf(fp2,"\nMOV %s,R0",result);
23+
fprintf(fp2, "\nMOV R0,%s", arg1);
24+
fprintf(fp2, "\nMUL R0,%s", arg2);
25+
fprintf(fp2, "\nMOV %s,R0", r);
2626
}
27-
if(strcmp(op,"-")==0)
27+
if (strcmp(op, "-") == 0)
2828
{
29-
fprintf(fp2,"\nMOV R0,%s",arg1);
30-
fprintf(fp2,"\nSUB R0,%s",arg2);
31-
fprintf(fp2,"\nMOV %s,R0",result);
29+
fprintf(fp2, "\nMOV R0,%s", arg1);
30+
fprintf(fp2, "\nSUB R0,%s", arg2);
31+
fprintf(fp2, "\nMOV %s,R0", r);
3232
}
33-
if(strcmp(op,"/")==0)
33+
if (strcmp(op, "/") == 0)
3434
{
35-
fprintf(fp2,"\nMOV R0,%s",arg1);
36-
fprintf(fp2,"\nDIV R0,%s",arg2);
37-
fprintf(fp2,"\nMOV %s,R0",result);
35+
fprintf(fp2, "\nMOV R0,%s", arg1);
36+
fprintf(fp2, "\nDIV R0,%s", arg2);
37+
fprintf(fp2, "\nMOV %s,R0", r);
3838
}
39-
if(strcmp(op,"=")==0)
39+
if (strcmp(op, "=") == 0)
4040
{
41-
fprintf(fp2,"\nMOV R0,%s",arg1);
42-
fprintf(fp2,"\nMOV %s,R0",result);
41+
fprintf(fp2, "\nMOV R0,%s", arg1);
42+
fprintf(fp2, "\nMOV %s,R0", r);
4343
}
44-
}
45-
fclose(fp1);
46-
fclose(fp2);
47-
// getch();
4844
}
49-
// }
45+
fclose(fp1);
46+
fclose(fp2);
47+
return 0;
48+
}

0 commit comments

Comments
 (0)