Program for the generation of assembly language code of relational operator

ALGORITHM:

  1. The three address code using the relational operator is get from the user.
  2. Identifying the addressing mode of the given three address code.
  3. Identify the relational operator used in the statement.
  4. Generate and display the assembly language code.
				
					#include

#include

#include

#include

#include

#include

void forswitch(char,int);

void conv(int);

char arg[10][10],op[5][2],ch[10],go[3][3],c[10];

void main()

{

int i=-1,m=0,k=10;

clrscr();

cout<<"\t\t\tTHREE ADDRESS CODE";

gotoxy(15,7);

cout<<"OPERATOR";

gotoxy(30,7);

cout<<"ARGUMENT-1";

gotoxy(45,7);

cout<<"ARGUMENT-2";

gotoxy(60,7);

cout<<"GOTO";

gotoxy(15,8);

cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~";

do

{

i++;

gotoxy(2,k);

printf("[%d]",i);

gotoxy(18,k);

scanf("%s",&op[i]);

forswitch(op[i][0],i);

gotoxy(33,k);

scanf("%s",&arg[m+i]);

gotoxy(48,k);

scanf("%s",&arg[m+1+i]);

gotoxy(61,k);

scanf("%s",&go[i]);

conv(m+i);

conv(m+1+i);

k++;

m++;

}while(i!=3);

clrscr();

printf("ASSEMBLY LANGUAGE CODE");

printf("\n\n100\tMOV %s,RO",arg[0]);

printf("\n101\tMOV %s,R1",arg[1]);

printf("\n102\tCMP R0,R1");

printf("\n103\t%s 107",ch);

printf("\n104\tMOV%s,R2",arg[3]);

printf("\n105\tMOV R2,%s",arg[2]);

printf("\n106\tJUMP 109");

printf("\n107\tMOV %s,R2",arg[5]);

printf("\n109\tend");

getch();

}

void conv(int x)

{

if(isdigit(arg[x][0]))

{

strcpy(c,"#");

strcat(c,arg[x]);

strcpy(arg[x],c);

}

}

void forswitch(char sh,int t)

{

if(t<1)

switch(sh)

{

case '<':

strcpy(ch,"JC");

break;

case '>':

strcpy(ch,"JNC");

break;

case '=':

strcpy(ch,"JZ");

break;

case '-':

break;

default:

gotoxy(8,40);

cout<<"\n\t\tINVALID ENTRY";

getch();

exit(0);

break;

}

}
[wp_ad_camp_1]
				
			
OUTPUT:
THREE ADDRESS CODE
OPERATOR   ARGUMENT1          ARGUMENT2                   GOTO

[0]          >                   date                       5                           [2]

[1]          =                   fine                       50                          [3]

[2]          =                   fine                        0                           ----

[3]           -                   ----                        ----                       end
ASSEMBLY LANGUAGE CODE

100  MOV date,R0

101  MOV #5,R1

102  CMP  R0,R1

103  JNC   107

104  MOV #50,R2

105  MOV R2,fine

106  JUMP 109

107   MOV #0,R2

108  MOV R2,fine

109  END 

Leave a Reply