我一直在嘗試編寫一些Java字節碼並使用Jasmin進行彙編。Java字節碼子程序 - 無法加載返回地址
我試圖讓我的周圍子程序的頭,我不知道爲什麼我跑我的程序時,得到如下錯誤信息:
>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
跳轉到單個子程序時,我沒有任何問題,但似乎跳轉到子程序內的子程序時出現問題。
任何有識之士爲什麼這是失敗的將不勝感激!
我不知道JVM的內部,但對正常的CPU 「登記」 $ 0始終爲0,不能通過彙編/字節碼設置。你確定這是可能的字節碼? – halfdan
我很確定使用「註冊」0是很好的。我已經嘗試了使用1而不是0的上述程序,並且我得到了相同的錯誤,但是「註冊」爲1. – Jack
好吧,只是一個瘋狂的猜測。 – halfdan