@printf "should be: %s\n" "Hello World"
./$< tests/Strings1 | egrep -c -e "^okay :-\)"
@printf "should be: %d\n" 3
+ ./$< tests/Array1 | grep "printstream"
+ @printf "should be: 0x%08x 0x%08x\n" 0x264 0x8
%.class: %.java
$(JAVAC) $<
import qualified Data.ByteString.Lazy as B
import Control.Monad
-import Foreign
+import Foreign hiding (xor)
import Foreign.C.Types
import Text.Printf
call (trapaddr - w32_calladdr)
add esp (4 :: Word32)
emit DUP = push (Disp 0, esp)
+ emit IASTORE = do
+ pop eax -- value
+ pop ebx -- offset
+ add ebx (1 :: Word32)
+ pop ecx -- aref
+ mov (ecx, ebx, S4) eax
+ emit IALOAD = do
+ pop ebx -- offset
+ add ebx (1 :: Word32)
+ pop ecx -- aref
+ push (ecx, ebx, S4)
emit ARRAYLENGTH = do
pop eax
push (Disp 0, eax)
emit IADD = do pop ebx; pop eax; add eax ebx; push eax
emit ISUB = do pop ebx; pop eax; sub eax ebx; push eax
emit IMUL = do pop ebx; pop eax; mul ebx; push eax
+ emit IXOR = do pop ebx; pop eax; xor eax ebx; push eax
emit (IINC x imm) = do
add (Disp (cArgs x), ebp) (s8_w32 imm)
public class Array1 {
public static void main(String []args) {
int []arr = new int[0x8];
- System.out.printf(arr.length);
+ int sum = 0;
+ for (int i = 0; i < 0x8; i++) {
+ arr[i] = (i + 1) * 0x11;
+ }
+ for (int i = 0; i < 0x8; i++) {
+ sum += arr[i];
+ }
+ System.out.printf(sum); // 0x264
+ System.out.printf(arr.length); // 0x8
}
}