www.daimi.au.dk/~smunk/dArkOS/uge41/
C-programmet, som implementerer IJVM, er ændret, så ordrerne imul, idiv, if_icmplt, ishl, ishr og iushr fra JVM er tilføjet. Det drejer sig om en udvidelse af switch-sætningen i ijvm_execute_opcode med:
Desuden er specifikationsfilen ændret til:case IJVM_OPCODE_IMUL: a = ijvm_pop (i); b = ijvm_pop (i); ijvm_push (i, a * b); break; case IJVM_OPCODE_IDIV: a = ijvm_pop (i); b = ijvm_pop (i); ijvm_push (i, b / a); break; case IJVM_OPCODE_IF_ICMPLT: offset = ijvm_fetch_int16 (i); a = ijvm_pop (i); b = ijvm_pop (i); if (a < b) i->pc = opc + offset; break; case IJVM_OPCODE_ISHL: a = ijvm_pop (i); b = ijvm_pop (i); a = a & 31; ijvm_push (i, b << a ); break; case IJVM_OPCODE_IUSHR: a = ijvm_pop (i); b = ijvm_pop (i); a = a & 31; ijvm_push (i,((uint32) b) >> a ); break; case IJVM_OPCODE_ISHR: a = ijvm_pop (i); b = ijvm_pop (i); a = a & 31; if ( b < 0 ) { b = ~b; b=b>>a; b = ~b; } else { b=b>>a; } ijvm_push (i, b ); break;
Endelig er de tilføjede ordrer blevet afprøvet af følgende program(mer):0x10 bipush byte 0x59 dup 0xA7 goto label 0x60 iadd 0x7E iand 0x99 ifeq label 0x9B iflt label 0x9F if_icmpeq label 0x84 iinc varnum, byte 0x15 iload varnum-wide 0xB6 invokevirtual method 0x80 ior 0xAC ireturn 0x36 istore varnum-wide 0x64 isub 0x13 ldc_w constant 0x00 nop 0x57 pop 0x5F swap 0xC4 wide 0x68 imul 0x6C idiv 0xA1 if_icmplt 0x78 ishl 0x7A ishr 0x7C iushr
Vi har valgt testdata, der afprøver metoderne for alle variationer af operander, dvs. både positive, negative og nul..method main .args 1 .define OBJREF = 44 bipush OBJREF 1 bipush 4 bipush 3 imul 2 bipush -3 bipush 4 imul 3 bipush 0 bipush 4 imul 4 bipush 12 bipush 3 idiv 5 bipush 12 bipush -3 idiv 6 bipush 0 bipush 3 idiv 7 bipush -12 bipush -3 idiv 8 bipush 12 bipush 2 ishl 9 bipush 12 bipush -2 ishl 10 bipush 12 bipush 0 ishl 11 bipush 12 bipush 2 ishr 12 bipush 12 bipush -2 ishr 13 bipush 12 bipush 0 ishr 14 bipush 12 bipush 2 iushr 15 bipush 12 bipush -2 iushr 16 bipush -12 bipush 2 iushr 17 bipush 12 bipush 0 iushr 18 bipush 0 bipush 2 iushr 19 bipush 0 bipush -2 iushr 20 st1: bipush 12 bipush -2 if_icmplt ok1 bipush 1 goto st2 ok1: bipush 0 21 st2: bipush -12 bipush 2 if_icmplt ok2 bipush 1 goto st3 ok2: bipush 0 22 st3: bipush 12 bipush 2 if_icmplt ok3 bipush 1 goto st4 ok3: bipush 0 23 st4: bipush -12 bipush -2 if_icmplt ok4 bipush 1 goto st5 ok4: bipush 0 24 st5: bipush 0 bipush 2 if_icmplt ok5 bipush 1 ireturn ok5: bipush 0 ireturn
Kørselsudskrift fra kørsel (kørsler) med afprøvningsprogrammet (programmerne):
Alle vore resultater er som forventet.IJVM Trace of test.bc Wed Oct 10 15:58:47 2001 stack = 0, 1, 45 bipush 44 [10 2c] stack = 44, 0, 1, 45 1 bipush 4 [10 04] stack = 4, 44, 0, 1, 45 bipush 3 [10 03] stack = 3, 4, 44, 0, 1, 45 imul [68] stack = 12, 44, 0, 1, 45 2 bipush -3 [10 fd] stack = -3, 12, 44, 0, 1, 45 bipush 4 [10 04] stack = 4, -3, 12, 44, 0, 1, 45 imul [68] stack = -12, 12, 44, 0, 1, 45 3 bipush 0 [10 00] stack = 0, -12, 12, 44, 0, 1, 45 bipush 4 [10 04] stack = 4, 0, -12, 12, 44, 0, 1, 45 imul [68] stack = 0, -12, 12, 44, 0, 1, 45 4 bipush 12 [10 0c] stack = 12, 0, -12, 12, 44, 0, 1, 45 bipush 3 [10 03] stack = 3, 12, 0, -12, 12, 44, 0, 1 idiv [6c] stack = 4, 0, -12, 12, 44, 0, 1, 45 5 bipush 12 [10 0c] stack = 12, 4, 0, -12, 12, 44, 0, 1 bipush -3 [10 fd] stack = -3, 12, 4, 0, -12, 12, 44, 0 idiv [6c] stack = -4, 4, 0, -12, 12, 44, 0, 1 6 bipush 0 [10 00] stack = 0, -4, 4, 0, -12, 12, 44, 0 bipush 3 [10 03] stack = 3, 0, -4, 4, 0, -12, 12, 44 idiv [6c] stack = 0, -4, 4, 0, -12, 12, 44, 0 7 bipush -12 [10 f4] stack = -12, 0, -4, 4, 0, -12, 12, 44 bipush -3 [10 fd] stack = -3, -12, 0, -4, 4, 0, -12, 12 idiv [6c] stack = 4, 0, -4, 4, 0, -12, 12, 44 8 bipush 12 [10 0c] stack = 12, 4, 0, -4, 4, 0, -12, 12 bipush 2 [10 02] stack = 2, 12, 4, 0, -4, 4, 0, -12 ishl [78] stack = 48, 4, 0, -4, 4, 0, -12, 12 9 bipush 12 [10 0c] stack = 12, 48, 4, 0, -4, 4, 0, -12 bipush -2 [10 fe] stack = -2, 12, 48, 4, 0, -4, 4, 0 ishl [78] stack = 0, 48, 4, 0, -4, 4, 0, -12 10 bipush 12 [10 0c] stack = 12, 0, 48, 4, 0, -4, 4, 0 bipush 0 [10 00] stack = 0, 12, 0, 48, 4, 0, -4, 4 ishl [78] stack = 12, 0, 48, 4, 0, -4, 4, 0 11 bipush 12 [10 0c] stack = 12, 12, 0, 48, 4, 0, -4, 4 bipush 2 [10 02] stack = 2, 12, 12, 0, 48, 4, 0, -4 ishr [7a] stack = 3, 12, 0, 48, 4, 0, -4, 4 12 bipush 12 [10 0c] stack = 12, 3, 12, 0, 48, 4, 0, -4 bipush -2 [10 fe] stack = -2, 12, 3, 12, 0, 48, 4, 0 ishr [7a] stack = 0, 3, 12, 0, 48, 4, 0, -4 13 bipush 12 [10 0c] stack = 12, 0, 3, 12, 0, 48, 4, 0 bipush 0 [10 00] stack = 0, 12, 0, 3, 12, 0, 48, 4 ishr [7a] stack = 12, 0, 3, 12, 0, 48, 4, 0 14 bipush 12 [10 0c] stack = 12, 12, 0, 3, 12, 0, 48, 4 bipush 2 [10 02] stack = 2, 12, 12, 0, 3, 12, 0, 48 iushr [7c] stack = 3, 12, 0, 3, 12, 0, 48, 4 15 bipush 12 [10 0c] stack = 12, 3, 12, 0, 3, 12, 0, 48 bipush -2 [10 fe] stack = -2, 12, 3, 12, 0, 3, 12, 0 iushr [7c] stack = 0, 3, 12, 0, 3, 12, 0, 48 16 bipush -12 [10 f4] stack = -12, 0, 3, 12, 0, 3, 12, 0 bipush 2 [10 02] stack = 2, -12, 0, 3, 12, 0, 3, 12 iushr [7c] stack = 1073741821, 0, 3, 12, 0, 3, 12, 0 17 bipush 12 [10 0c] stack = 12, 1073741821, 0, 3, 12, 0, 3, 12 bipush 0 [10 00] stack = 0, 12, 1073741821, 0, 3, 12, 0, 3 iushr [7c] stack = 12, 1073741821, 0, 3, 12, 0, 3, 12 18 bipush 0 [10 00] stack = 0, 12, 1073741821, 0, 3, 12, 0, 3 bipush 2 [10 02] stack = 2, 0, 12, 1073741821, 0, 3, 12, 0 iushr [7c] stack = 0, 12, 1073741821, 0, 3, 12, 0, 3 19 bipush 0 [10 00] stack = 0, 0, 12, 1073741821, 0, 3, 12, 0 bipush -2 [10 fe] stack = -2, 0, 0, 12, 1073741821, 0, 3, 12 iushr [7c] stack = 0, 0, 12, 1073741821, 0, 3, 12, 0 20 bipush 12 [10 0c] stack = 12, 0, 0, 12, 1073741821, 0, 3, 12 bipush -2 [10 fe] stack = -2, 12, 0, 0, 12, 1073741821, 0, 3 if_icmplt 8 [a1 00 08] stack = 0, 0, 12, 1073741821, 0, 3, 12, 0 bipush 0 [10 00] stack = 0, 0, 0, 12, 1073741821, 0, 3, 12 21 bipush -12 [10 f4] stack = -12, 0, 0, 0, 12, 1073741821, 0, 3 bipush 2 [10 02] stack = 2, -12, 0, 0, 0, 12, 1073741821, 0 if_icmplt 8 [a1 00 08] stack = 0, 0, 0, 12, 1073741821, 0, 3, 12 bipush 1 [10 01] stack = 1, 0, 0, 0, 12, 1073741821, 0, 3 goto 5 [a7 00 05] stack = 1, 0, 0, 0, 12, 1073741821,0, 3 22 bipush 12 [10 0c] stack = 12, 1, 0, 0, 0, 12, 1073741821, 0 bipush 2 [10 02] stack = 2, 12, 1, 0, 0, 0, 12, 1073741821 if_icmplt 8 [a1 00 08] stack = 1, 0, 0, 0, 12, 1073741821,0, 3 bipush 0 [10 00] stack = 0, 1, 0, 0, 0, 12, 1073741821, 0 23 bipush -12 [10 f4] stack = -12, 0, 1, 0, 0, 0, 12, 1073741821 bipush -2 [10 fe] stack = -2, -12, 0, 1, 0, 0, 0, 12 if_icmplt 8 [a1 00 08] stack = 0, 1, 0, 0, 0, 12, 1073741821, 0 bipush 1 [10 01] stack = 1, 0, 1, 0, 0, 0, 12, 1073741821 goto 5 [a7 00 05] stack = 1, 0, 1, 0, 0, 0, 12, 1073741821 24 bipush 0 [10 00] stack = 0, 1, 0, 1, 0, 0, 0, 12 bipush 2 [10 02] stack = 2, 0, 1, 0, 1, 0, 0, 0 if_icmplt 6 [a1 00 06] stack = 1, 0, 1, 0, 0, 0, 12, 1073741821 bipush 1 [10 01] stack = 1, 1, 0, 1, 0, 0, 0, 12 ireturn [ac] stack = 1 return value: 1