public class VirtualMachine implements VMConstants{ static VmInstruction c[]=new VmInstruction[codeLength]; static int[] s = new int[stackLength]; static int p; static int t; static byte f; static int a; public static void main (String[] arg){ /* Methode erwartet ein Array als Parameter und der Name sollte ohne Leerzeichen gewählt werden. Der Conpiler besitzt keine KI */ Load VmProgram(); p=0; t=-1; f=c[0].fct; a=c[0].attribute; /* Was soll das Programm machen while(f!=RET)*/ while (f!=RET) } public static void ShowInstruction(boolean before){ System.out.println(); System.out.println("fct="+mnemonic[f]+"value"+a); if (!before) { for (int i=0; i<=t; i=i++){ System.out.println("fct"+f+"value"+a); } System.out.println(); } } public static void execInstruction(byte f,int a){ switch (f) { case INT:{t=t+a; break;} case LIT:{t=t++; s[t] = val; break;} case LOD:{t=t++; s[t] = s[adr]; break;} case STO:{s[adr] = s[t]; t=t-1; break;} case OPR:{operation(a); break;} case JMP:{p=q; break;} case JPC:{if (s[t] ==1) p=q; t=t-1; break;} case CAL:{break;} case RET:{break;} default:{System.out.println("ERROR"); break;} } } /* Wie schon gesagt keine Leerzeichen im Methodennamen */ public static void Load VmProgram(String[] b){ c[0]=VmInstruction (INT,5); c[1]=VmInstruction (OPR,6); c[2]=VmInstruction (STO,0); c[3]=VmInstruction (OPR,6); c[4]=VmInstruction (STO,1); c[5]=VmInstruction (OPR,6); c[6]=VmInstruction (STO,2); c[7]=VmInstruction (OPR,6); c[8]=VmInstruction (STO,3); c[9]=VmInstruction (LOD,0); c[10]=VmInstruction (LOD,1); c[11]=VmInstruction (OPR,4); c[12]=VmInstruction (LOD,2); c[13]=VmInstruction (LOD,3); c[14]=VmInstruction (OPR,4); c[15]=VmInstruction (OPR,2); c[16]=VmInstruction (STO,4); c[17]=VmInstruction (LOD,4); c[18]=VmInstruction (OPR,7); c[19]=VmInstruction (RET,0); } public static void operation(int a){ switch(a){ case (a==1):{s[t]=-s[t]; break;} case (a==2):{t=t-1; s[t]=s[t]+s[t+1]; break;} case (a==3):{t=t-1; s[t]=s[t]-s[t+1]; break;} case (a==4):{t=t-1; s[t]=s[t]*s[t+1]; break;} case (a==5):{t=t-1; s[t]=s[t]/s[t+1]; break;} case (a==6):{t=t+1; READ(s[t]); break;} case (a==7):{WRITE(s[t]); t=t-1; break;} /* Ein oder in Java sieht eher so aus: "||" oder so "|" */ case (a==8):{t=t-1; s[t]=0 oder 1; break;} case (a==9):{t=t-1; s[t]=0 oder 1; break;} case (a==10):{t=t-1; s[t]=0 oder 1; break;} case (a==11):{t=t-1; s[t]=0 oder 1; break;} case (a==12):{t=t-1; s[t]=0 oder 1; break;} case (a==13):{t=t-1; s[t]=0 oder 1; break;} } }}