Ex. No: 10
Date:
10. Implement
the back end of the compiler which takes the three address code and produces the
8086 assembly language instructions that can be assembled and run using a 8086 assembler.
The target assembly instructions can be simple move, add, sub, jump. Also simple addressing modes are used.
To write a C program to implement the Back end of the compiler.
ALGORITHM:
1. Start the program.
2. Get the three variables from statements and stored in the text file k.txt.
3. Compile the program and give the path of the source file.
4. Execute the program.
5. Target code for the given statement was produced.
6. Stop the program.
PROGRAM
#include <stdio.h >
#include <stdio.h >
#include<conio.h>
#include <string.h >
void main() {
char icode[10][30], str[20], opr[10];
int i = 0;
clrscr();
printf("\n Enter the set of intermediate code (terminated by exit):\n");
do
{
scanf("%s", icode[i]);
} while (strcmp(icode[i++], "exit") != 0);
printf("\n target code generation");
printf("\n************************");
i = 0;
do {
strcpy(str, icode[i]);
switch (str[3]) {
case '+':
strcpy(opr, "ADD ");
break;
case '-':
strcpy(opr, "SUB ");
break;
case '*':
strcpy(opr, "MUL ");
break;
case '/':
strcpy(opr, "DIV ");
break;
}
printf("\n\tMov %c,R%d", str[2], i);
printf("\n\t%s%c,R%d", opr, str[4], i);
printf("\n\tMov R%d,%c", i, str[0]);
} while (strcmp(icode[++i], "exit") != 0);
getch();
}
OUTPUT:
Enter the set of intermediate code (terminated by exit):
a=a*b
c=f*h
g=a*h
f=Q+w
t=q-j
exit
target code generation
************************
Mov a,R0
MUL b,R0
Mov R0,a
Mov f,R1
MUL h,R1
Mov R1,c
Mov a,R2
MUL h,R2
Mov R2,g
Mov Q,R3
ADD w,R3
Mov R3,f
Mov q,R4
SUB j,R4
Mov R4,t
RESULT:
Thus the above program is compiled and executed successfully and output is verified.
This is amazing post plz Visit HTML Compiler Crack
ReplyDeleteI'm really impressed with your writing skills, as smart as the structure of your
ReplyDeleteLatest Software Free Download
weblog. Is this a paid topic
Mediacoder crack
do you change it yourself? However, stopping by with great quality writing, it's hard to see any good blog today.
Push video wallpaper -crack
Iobit start menu -crack
Pinnacle pro -crack
html compiler pro crack
This was an amazing post
ReplyDeleteCool and I have a nifty provide: Who Does Renovations home renovation in canada
ReplyDelete