我一直在尝试编写一些Java字节码,并使用Jasmin进行组装。
我试图得到我的头周围的子程序,我不知道为什么我获得以下错误信息时,运行我的程序:
>java -jar jasmin.jar test.j
Generated: test.class
>java test
Exception in thread "main" java.lang.VerifyError: (class: test,
method: main signature: ([Ljava/lang/String;)V)
Cannot load return address from register 0
Could not find the main class: test. Program will exit.
下面是test.j中的字节码:
.class public test
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 6
.limit locals 5
jsr a ;Jump to subroutine 'a', pushing return address on operand stack
return ;Exit the program
a:
astore_0 ;Store the return address in variable 0
aload_0 ;Save the address onto the stack as address will be overwritten in 'b'
jsr b ;Jump to subroutine 'b', pushing return address on operand stack
astore_0 ;Store the address that was on the stack back into variable 0
ret 0 ;Return to just after "jsr a"
b:
astore_0 ;Store return address in variable 0
ret 0 ;Return to address stored in 0 (ie back to just after the jump in 'a')
.end method
我在跳转到单个子例程时没有遇到任何问题,但是当从子例程内跳转到子例程时,似乎有些事情出错了。
任何关于为什么这是失败的见解将非常感激!
您不能将地址类型值加载到任何寄存器中,您只能存储它,然后ret指令可以从那里检索它。
Java Virtual Machine Specification:
- ret jsr