www.daimi.au.dk/~smunk/dArkOS/uge49/
Programmet er udvidet så de nye ordrer også kan fortolkes. Tilføjelserne ser således ud:
Specifikationsfilen ser således ud:# Made by US ########################################## # MDR = z, TOS = x, OPC = y imul = 0x68: MAR = SP = SP - 1; rd H = TOS OPC = MDR MDR = 0 N = TOS; if (N) goto imul_neg; else goto imul_test imul_neg: MDR = LV; wr TOS = -H LV = MDR = 0; goto imul_test imul_test: Z = TOS; if (Z) goto imul_end; else goto imul_while imul_while: H = 1 Z = H AND TOS; if (Z) goto imul_lige; else goto imul_ulige imul_lige: H = TOS TOS = H >> 1 H = OPC OPC = OPC + H; goto imul_test imul_ulige: H = OPC MDR = MDR + H; goto imul_lige imul_invert: LV = MDR H = -H; goto imul_finish_end imul_end: H = MDR; rd Z = LV; if (Z) goto imul_invert; else goto imul_finish_end imul_finish_end: TOS = MDR = H; wr; goto main ########################################## # TOS = w(y), OPC = r(x), MDR = q, LV = y idiv = 0x6c: MAR = SP = SP - 1; rd H = LV OPC = MDR MDR = H; wr MAR = SP = SP + 1 H = LV = TOS MDR = CPP; wr empty MDR = CPP = 0 N = TOS; if (N) goto idiv_neg; else goto idiv_test3 idiv_neg: TOS = LV = H = -H CPP = 1 MDR = 0; goto idiv_test3 idiv_test3: N = OPC; if (N) goto idiv_neg2; else goto idiv_test1 idiv_neg2: H = OPC OPC = -H H = LV CPP = CPP - 1; goto idiv_test1 idiv_test1: N = OPC - H; if (N) goto idiv_end; else goto idiv_while1 idiv_while1: H = TOS = TOS + H; goto idiv_test1 idiv_end: H = TOS; goto idiv_test2 idiv_test2: Z = LV - H; if (Z) goto idiv_end2; else goto idiv_while2 idiv_while2: TOS = H >> 1 H = MDR MDR = MDR + H H = TOS N = OPC - H; if (N) goto idiv_test2; else goto idiv_st idiv_st: MDR = MDR + 1 OPC = OPC - H; goto idiv_test2 idiv_end2: H = MDR; rd Z = CPP; if (Z) goto idiv_finish_end; else goto idiv_invert idiv_invert: H = - H; goto idiv_finish_end idiv_finish_end: MAR = SP = SP - 1 CPP = MDR; rd empty LV = MDR TOS = MDR = H; wr; goto main ########################################## ishl = 0x78: MAR = SP = SP - 1; rd empty ishl_test: Z = TOS; if (Z) goto ishl_end; else goto ishl_st ishl_st: H = MDR MDR = MDR + H TOS = TOS - 1; goto ishl_test ishl_end: TOS = MDR; wr goto main ########################################## ishr = 0x7A: MAR = SP = SP - 1; rd OPC = 1 << 8 OPC = OPC >> 1 OPC = OPC >> 1 OPC = OPC >> 1 H = OPC - 1 TOS = H AND TOS ishr_while: TOS = TOS - 1; if (N) goto ishr_endwhile; else goto ishr_do ishr_do: MDR = MDR >> 1; goto ishr_while ishr_endwhile: TOS = MDR; wr; goto main iushr = 0x7c: MAR = SP = SP - 1; rd H = 1 H = H << 8 H = H << 8 H = H << 8 H = H >> 1 H = H << 8 iushr_test: Z = TOS; if (Z) goto iushr_end; else goto iushr_st iushr_st: MDR = MDR >> 1 TOS = TOS - 1 Z = MDR AND H; if (Z) goto iushr_test; else goto iushr_st2 iushr_st2: MDR = MDR - H; goto iushr_test iushr_end: TOS = MDR; wr; goto main ########################################## if_icmplt = 0xA1: MAR = SP = SP - 1; rd MAR = SP = SP - 1 OPC = TOS; if (N) goto yNeg; else goto yPos yNeg: H = MDR; if (N) goto if_icmpltNEG; else goto if_icmpltF yPos: H = MDR; if (N) goto if_icmpltT; else goto if_icmpltPOS if_icmpltT: goto T if_icmpltF: goto F if_icmpltPOS: goto if_icmplt_end if_icmpltNEG: goto if_icmplt_end if_icmplt_end: H = OPC OPC = MDR - H; if (N) goto T; else goto F
Resultatet af kørsel med JVM program:0x68 imul 0x6C idiv 0xA1 if_icmplt label 0x78 ishl 0x7A ishr 0x7C iushr
blev:.method main .args 1 .define OBJREF = 42 bipush OBJREF uha: bipush 35 // stack = 35 bipush 2 // stack = 2, 35 bipush 4 // stack = 4, 2, 35 imul // stack = 8, 35 idiv // stack = 4 bipush 2 // stack = 2, 4 ishl // stack = 16 bipush 2 // stack = 2, 16 iushr // stack = 4 bipush 8 // stack = 8, 4 isub // stack = -4 bipush 2 // stack = 2, -4 ishr // stack = -1 bipush -2 // stack = -2, -1 if_icmplt uha // stack = bipush 0 // stack = 0 ireturn // return 0
Resultatet blev som forventet, Det hele virker bare. Vores ishl, ishr og iushr nægter at bruge negative tal som operander, men vi kan ikke se hvordan de skulle virke med dem.Mic1 Trace of ijvm.mic1 with test.bc Mon Dec 10 17:59:01 2001 stack = 0, 1, 11 bipush 42 [10 2a] stack = 42, 0, 1, 11 bipush 35 [10 23] stack = 35, 42, 0, 1, 11 bipush 2 [10 02] stack = 2, 35, 42, 0, 1, 11 bipush 4 [10 04] stack = 4, 2, 35, 42, 0, 1, 11 imul [68] stack = 8, 35, 42, 0, 1, 11 idiv [6c] stack = 4, 42, 0, 1, 11 bipush 2 [10 02] stack = 2, 4, 42, 0, 1, 11 ishl [78] stack = 16, 42, 0, 1, 11 bipush 2 [10 02] stack = 2, 16, 42, 0, 1, 11 iushr [7c] stack = 4, 42, 0, 1, 11 bipush 8 [10 08] stack = 8, 4, 42, 0, 1, 11 isub [64] stack = -4, 42, 0, 1, 11 bipush 2 [10 02] stack = 2, -4, 42, 0, 1, 11 ishr [7a] stack = -1, 42, 0, 1, 11 bipush -2 [10 fe] stack = -2, -1, 42, 0, 1, 11 if_icmplt -22 [a1 ff ea] stack = 42, 0, 1, 11 bipush 0 [10 00] stack = 0, 42, 0, 1, 11 ireturn [ac] stack = 0 return value: 0