簡單機器語言的模擬 (轉)

amyz發表於2007-08-15
簡單機器語言的模擬 (轉)[@more@]

有這麼多指令:10讀11寫21讀緩衝30-33加減成除40-42轉向

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

for(int i=0;i<100;i++)
{
int temp;
cin>>temp;
if(temp==-99999)
{
cout<}
if(temp>9999)
{
cout<continue;
}
if(temp{
cout<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< counter=-1;break;
default:cout<}
}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-957935/,如需轉載,請註明出處,否則將追究法律責任。

相關文章