我目前陷入以下问题:
尝试执行下面的代码,我收到“寄存器 1 包含错误类型”的 java 错误。由于我只使用 1 个堆栈块整数,我真的想知道错误类型是如何进入该寄存器的。下面是我的 jasmin-java-bytecode,它编译得很好,但是在执行时会抛出该错误。
.class public HelloWorld .super java/lang/Object
.method public static fakultaet(I)I
.limit locals 100
.limit stack 100
ldc 4
istore 0
ldc 1
istore 2
START:
iload 0
iload 2
isub
ifne ENDE
iload 0
ldc 1
imul
istore 1
iload 2
ldc 1
iadd
istore 2
goto START
ENDE:
getstatic java/lang/System/out Ljava/io/PrintStream;
iload 1
invokevirtual java/io/PrintStream/println(I)V
iload 1
ireturn
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 100
.limit locals 100
ldc 1
istore 0
ldc 2.0
fstore 1
ldc 3
istore 2
ldc 3
ldc 2
iadd
istore 0
ldc 3
invokestatic HelloWorld/fakultaet(I)I
return
.end method
这是生成的错误:
Exception in thread "main" java.lang.VerifyError: (class: HelloWorld, method: fakultaet signature: (I)I) Register 1 contains wrong type
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)