asm打印局部变量,asm打印变量,
分享于 点击 45038 次 点评:45
asm打印局部变量,asm打印变量,
//main method { MethodVisitor mv=cw.visitMethod(ACC_PUBLIC+ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); //create a local variable and store it at index=1 //example source code: int c=10; mv.visitIntInsn(BIPUSH, 10); //put constant 10 to the stack mv.visitVarInsn(ISTORE,1);//save value on the stack in index 1 mv.visitFieldInsn(GETSTATIC, "java/lang/System","out", "Ljava/io/PrintStream;"); mv.visitVarInsn(ILOAD,1); // load the variable 1 onto the stack mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(I)V"); //output 10 mv.visitInsn(RETURN); mv.visitMaxs(2,2); mv.visitEnd(); }
用户点评