有这么多指令:10读11写21读缓冲30-33加减成除40-42转向
#include
void main()
{
int memory[100],instr,code,oper,acc,counter(0);
cout<<"welcome to Simpletron"<
<endl;
for(int i=0;i<100;i++)
{
int temp;
cin>>temp;
if(temp==-99999)
{
cout<<"program execution begins"<
<endl;break;
}
if(temp>9999)
{
cout<<"error"<
<endl;i=i-1;
continue;
}
if(temp<-9999)
{
cout<<"error"<
<endl;i=i-1;
continue;
}
memory[i]=temp;
}
while(1)
{
if(counter==-1)
break;
instr=memory[counter];
code=instr/100;
oper=instr%100;
switch(code)
{
case 10:cout<<"?"<
<endl;cin>>memory[oper];
counter++;break;
case 11:cout<
case 20:acc=memory[oper];counter++;break;
case 21:memory[oper]=acc;counter++;break;
case 30:acc+=memory[oper];counter++;break;
case 31:acc-=memory[oper];counter++;break;
case 32:acc*=memory[oper];counter++;break;
case 33:acc/=memory[oper];counter++;break;
case 40:counter=oper;break;
case 41:if(acc<0)
counter=oper;break;
case 42:if(acc==0)
counter=oper;break;
case 43:cout<<"Simpletron excution terminated"<<endl;
counter=-1;break;
default:cout<<"error"<
<endl;}
}
}