ITPub博客

首页 > 应用开发 > IT综合 > 简单机器语言的模拟 (转)

简单机器语言的模拟 (转)

原创 IT综合 作者:amyz 时间:2007-08-15 12:53:01 0 删除 编辑
简单机器语言的模拟 (转)[@more@]

有这么多指令:10读11写21读缓冲30-33加减成除40-42转向

#include
void main()
{
int memory[100],instr,code,oper,acc,counter(0);
cout<<"welcome to Simpletron"<

for(int i=0;i<100;i++)
{
int temp;
cin>>temp;
if(temp==-99999)
{
cout<<"program execution begins"<}
if(temp>9999)
{
cout<<"error"<continue;
}
if(temp<-9999)
{
cout<<"error"<continue;
}
memory[i]=temp;
}
while(1)
{
if(counter==-1)
break;
instr=memory[counter];
code=instr/100;
oper=instr%100;
switch(code)
{
case 10:cout<<"?"<>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"< counter=-1;break;
default:cout<<"error"<}
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-957935/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3982
  • 访问量
    7895717