Created
November 12, 2020 06:17
-
-
Save blacksmithop/d5ddf817bb337377988d715a67776386 to your computer and use it in GitHub Desktop.
Intermediate Code -> Target Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void main(){ | |
char icode[10][30], str[30], opr[30]; | |
int i=0; | |
printf("Enter Intermediate Code (terminated by exit):\n"); | |
do{ | |
scanf("%s", icode[i]); | |
}while(strcmp(icode[i++], "exit") !=0); | |
printf("Target Code Generator\n"); | |
i = 0; | |
do{ | |
strcpy(str, icode[i]); | |
switch (str[3]) { //this is where symbols are | |
case '+': | |
strcpy(opr, "ADD"); | |
break; | |
case '-': | |
strcpy(opr, "SUB"); | |
break; | |
case '*': | |
strcpy(opr, "MUL"); | |
break; | |
case '/': | |
strcpy(opr, "DIV"); | |
break; | |
} | |
printf("\nMOV %c,R%d",str[2],i); | |
printf("\n%s %c,R%d",opr,str[4],i); | |
printf("\nMOV R%d,%c",i,str[0]); | |
}while(strcmp(icode[++i], "exit") !=0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment