首页 > 应用开发 > IT综合 > 简单机器语言的模拟 (转)
有这么多指令:10读11写21读缓冲30-33加减成除40-42转向
#include for(int i=0;i<100;i++)
void main()
{
int memory[100],instr,code,oper,acc,counter(0);
cout<<"welcome to Simpletron"<
{
int temp;
cin>>temp;
if(temp==-99999)
{
cout<<"program execution begins"<
if(temp>9999)
{
cout<<"error"<
}
if(temp<-9999)
{
cout<<"error"<
}
memory[i]=temp;
}
while(1)
{
if(counter==-1)
break;
instr=memory[counter];
code=instr/100;
oper=instr%100;
switch(code)
{
case 10:cout<<"?"<
counter++;break;
case 11:cout<
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"<
default:cout<<"error"<
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-957935/ ,如需转载,请注明出处,否则将追究法律责任。