Choose Category
#include<iostream.h> #include<conio.h> #include<string.h> struct sm { char name[24],code[50][50],a[10]; int addr,ac,stmt,i; }b[15]; void action(int z) { cout<<"\n"<<b[z].addr<<":\t"<<"Action\n"; b[z].addr=b[z].addr+20; } void halt(int z) { cout<<"\n"<<b[z].addr<<":\t"<<"Halt\n"; } void call(int z,int x,int y) { cout<<"\n"<<b[z].addr<<":\t"<<"MOV #"<<b[z].addr+20<<","<<x<<"\n"; b[z].addr=b[z].addr+12; cout<<"\n"<<b[z].addr<<":\t"<<"Goto "<<y<<"\n"; b[z].addr=b[z].addr+8; } void returns(int z) { cout<<"\n"<<b[z].addr<<":\t"<<"Goto "<<b[z].ac<<"\n"; } void main() { int i,j,k,n,d,e,s,t; char c[24]; clrscr(); cout<<"\t\t\tRUN TIME STORAGE MANAGEMENT"; cout<<"\nEnter Ur Procedure Number:"; cin>>n; for(i=0;i<n;i++) { cout<<"\nPROCEDURE NAME :"; cin>>b[i].name; cout<<"\nEnter # of Statements ;"; cin>>b[i].stmt; cout<<"\nStarting addr of the Activation Record :"; cin>>b[i].ac; cout<<"\nEnter The Starting Address :"; cin>>b[i].addr; cout<<"\nEnter The Statements :"; for(j=0;j<b[i].stmt;j++) { cin>>b[i].code[j]; if(strcmp(b[i].code[j],"call")==0) cin>>b[i].a[j]; else b[i].a[j]='*'; } } for(i=0;i<n;i++) { for(j=0;j<b[i].stmt;j++) { if(strcmp(b[i].code[j],"action")==0) action(i); if(strcmp(b[i].code[j],"halt")==0) halt(i); else if(strcmp(b[i].code[j],"call")==0) { c[0]=b[i].a[j]; c[1]='\0'; for(k=0;k<n;k++) { if(strcmp(b[k].name,c)==0) { e=b[k].addr; d=b[k].ac; } } call(i,d,e); } else { returns(i); } } } getch(); }