简单机器语言的模拟

王朝vc·作者佚名  2006-01-08
宽屏版  字体: |||超大  

有这么多指令: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;}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有