www.daimi.au.dk/~smunk/dArkOS/uge43/
Funktionen readhex er programmeret til IJVM som følgende metode:
Et simpelt hovedprogram har været brugt til afprøvning. Hovedprogrammet og en række kørsler af dette ser således ud:.method readhex .args 1 .define OBJREF = 51 .locals 4 .define num = 1 .define digit = 2 .define i = 3 .define c = 4 bipush 3 bipush 0 istore num istore i while: iload i iflt end_while bipush OBJREF invokevirtual getchar istore c // c = getchar(); Taltest: bipush 47 iload c if_icmplt Taltest2 goto error Taltest2: iload c bipush 58 if_icmplt Tal goto lbtest1 lbtest1: bipush 96 iload c if_icmplt lbtest2 goto error lbtest2: iload c bipush 103 if_icmplt bogstav goto error bogstav: iload c bipush 87 goto common Tal: iload c bipush 48 goto common common: isub istore digit iload num bipush 4 ishl iload digit iadd istore num iload i bipush 1 isub istore i goto while error: bipush OBJREF bipush 45 invokevirtual putchar istore c goto while end_while: iload num ireturn
Vi har afprøvet yderpunterne og et par midt i, og vi har prøvet med ugyldigt testdata, som blot bliver ignoreret, men hvor vi udskriver et "-" til skærmen..method main .args 1 .define OBJREF = 42 bipush OBJREF invokevirtual readhex ireturn [1111] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: 4369 [0000] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: 0 [0001] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: 1 [ffff] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: 65535 [5675] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: 22133 [mlivafff] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc ----return value: 45055 [llllll456f] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc ------return value: 17775
Endelig er readhex ændret så ikke-hexadecimale cifre resulterer i en returnering af -1 fra metoden:
Kørselsudskrift fra kørslel med fejl i de hexadecimale tal:.method readhex .args 1 .define OBJREF = 51 .locals 4 .define num = 1 .define digit = 2 .define i = 3 .define c = 4 bipush 3 bipush 0 istore num istore i while: iload i iflt end_while bipush OBJREF invokevirtual getchar istore c // c = getchar(); Taltest: bipush 47 iload c if_icmplt Taltest2 goto error Taltest2: iload c bipush 58 if_icmplt Tal goto lbtest1 lbtest1: bipush 96 iload c if_icmplt lbtest2 goto error lbtest2: iload c bipush 103 if_icmplt bogstav goto error bogstav: iload c bipush 87 goto common Tal: iload c bipush 48 goto common common: isub istore digit iload num bipush 4 ishl iload digit iadd istore num iload i bipush 1 isub istore i goto while error: bipush -1 ireturn goto while end_while: iload num ireturn
[m] [smunk@commodus:~/dArkOS/uge43]$ ../uge41/ijvm -s readhex.bc return value: -1