Search code examples
javacompiler-constructionjvmjasmin

Jasmin assembler using array assignment satements


var a int[1];
var aa int[1];
aa = a;

Suppose we wanted to compile something like this in java jvm. It would seam that one would just do a

ldc 1
newarray    int
astore  0
ldc 1
newarray    int
astore  1
aload   0
istore  1

However this is not work it is throwing a (class: test, method: main signature: ()V) Expecting to find integer on stack Can you not aload an array into a local variable?


Solution

  • It's the istore instruction causing the problem. In the Virtual Machine Specification it's defined to

    Store int into local variable

    You're trying to store the array reference, so astore is the correct instruction type, just the way you did it after the newarray instructions.