CLASS FELLOWS CHOR KER AB JUNIORS B PECHAY PER GAYE HAIN, YAR YE ASSIGNMENT MILI HAI, YAR IS SUBJECT KA KOI PROJECT BANANA HAI.YAR YE ABEEL NISAR JO HAI NA BARA HI ZAHEEN BACHA HAI, IS KO SUB KUCH ATA HAI.
ABEEL NISAR KOI UPPER SE SEIKH KER AYA THA,YA AASMAN SE SUB KUCH UTARTA HAI MERE DAMAGH MEI, WATT LAGAO SAREY MILL KER MERI, JIS DIN SHIRAFAT KA JANAZA NIKAL GAYA NA TO MEI TUM SUB KI WATT LAGA DU GA.I REALLY MEAN IT.
ISS LIYE THORA HOLA HATH RAKHO OR KISI DOSRAY KA BHI KHAYAL KAR LIYA KARO.TUMHARA MATLAB PURA HO GA TO TUM LOGO NE SALAM KA JAWAB BHI NHI DENA.)
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
class microsimulator
{
private:
int ir;float acc;
int mem[2][32];
public:
int pc;
//Constructor
microsimulator()
{
pc=1;
ir=0;
acc=15;
mem[2][32]=0;
}
//Method for user interface
void user()
{ int i;
cout<<"***--------NOTE-----------***"<<endl;
cout<<">>Memory is 32-bit, first 16-bit for addresses and their instructions"<<endl;
cout<<" remaining 16-bit for addresses and their data"<<endl<<endl;
cout<<">>Instructions should be of 3-digit that consist of an opcode and address"<<endl<<endl;
cout<<">>Opcode with their operations"<<endl;
cout<<"1.Add"<<endl;
cout<<"2.Subtract"<<endl;
cout<<"3.Multiply"<<endl;
cout<<"4.Divide"<<endl;
cout<<"5.Move"<<endl;
cout<<"6.Move X"<<endl<<endl;
for(i=0;i<16;i++)
{
cout<<"Enter address"<<endl;
cin>>mem[0][i];
cout<<"enter its 3-digit instruction"<<endl;
cin>>mem[1][i];
}
for(int j=16;j<32;j++)
{
cout<<"enter address"<<endl;
cin>>mem[0][j];
cout<<"enter its corresponding data"<<endl;
cin>>mem[1][j];
}
}
//Method for search
void find1()
{
for(int h=0;h<16;h++)
{
if(pc==mem[0][h])
{
ir=mem[1][h];
}
}
}
//Method for decoding
int dec1()
{ int b=ir/100;
return b;
}
//Method for decoding
int dec2()
{
int c=ir%100;
return c;
}
//Method for search
int find2(int c)
{ int d;
for(int h=16;h<32;h++)
{
if(c==mem[0][h])
{
d=mem[1][h];
}
}
return d;
}
//Method for arithmetic operations of ALU
void alu(int op,int d)
{
if(op==1)
{ acc=acc+d;
pc++;
}
else if(op==2)
{ acc=acc-d;
pc++;
}
else if(op==3)
{ acc=acc*d;
pc++;
}
else if(op==4)
{ acc=acc/d;
pc++;
}
else if(op==5)
{ d=acc;
pc++;
}
else if(op==6)
{ acc=d;
}
else
cout<<"Invalid opcode"<<endl;
}
//Method for display
void display()
{
cout<<"pc= "<<pc<<endl;
cout<<"ir= "<<ir<<endl;
cout<<"acc= "<<acc<<endl;
for(int j=0;j<32;j++)
{
cout<<"MEMORY location" <<j<<endl;
cout<<"-------"<<endl;
cout<<"ADDRESS "<<mem[0][j]<<endl;
cout<<"DATA "<<mem[1][j]<<endl;
cout<<"-------"<<endl;
}
}
}; //end of class
void main()
{ clrscr();
microsimulator s;
int a,b,d,pc;
s.user();
pc=s.pc;
for(pc=1;pc<17;pc++)
{
s.find1();
a=s.dec1();
b=s.dec2();
d=s.find2(b);
s.alu(a,d);
}
s.display();
getche();
}