rpowerの例

instance.rpower(2, 4),すなわち2の4乗計算の様子を説明する.
プログラムは,
.method rpower(II)I
    .limit stack 5  ; スタックサイズ=5
    .limit locals 3 ; ローカル変数サイズ=3 
;---- [this, a, b]
    iload_2
    ifle Label1
    iload_1
    aload_0
    iload_1
    iload_2
    iconst_1
    isub
    invokevirtual Calc/rpower(II)I
    imul
    ireturn
Label1:
    iconst_1
    ireturn
.end method

this.rpower(2, 4)の呼び出し
local=[this, 2, 4] stack=[]
iload_2
local=[this, 2, 4] stack=[4]
ifle Label1 ; スタックトップが0以下ならLabel1にジャンプ,p.343
local=[this, 2, 4] stack=[]
iload_1
local=[this, 2, 4] stack=[2, ]
aload_0
local=[this, 2, 4] stack=[2, this]
iload_1
iload_2
local=[this, 2, 4] stack=[2, this, 2, 4]
iconst_1
local=[this, 2, 4] stack=[2, this, 2, 4, 1]
isub
local=[this, 2, 4] stack=[2, this, 2, 3]
invokevirtual Calc/rpower(II)I ; this.rpower(2, 3)の呼び出し,新しいフレーム作成
local=[this, 2, 4] stack=[2, 8]
imul
local=[this, 2, 4] stack=[16]
ireturn ; スタックトップの16を呼び出し側に返す

this.rpower(2, 3)の呼び出し
local=[this, 2, 3] stack=[]
iload_2
local=[this, 2, 3] stack=[3]
ifle Label1 ; スタックトップが0以下ならLabel1にジャンプ,p.343
local=[this, 2, 3] stack=[]
iload_1
local=[this, 2, 3] stack=[2, ]
aload_0
local=[this, 2, 3] stack=[2, this]
iload_1
iload_2
local=[this, 2, 3] stack=[2, this, 2, 3]
iconst_1
local=[this, 2, 3] stack=[2, this, 2, 3, 1]
isub
local=[this, 2, 3] stack=[2, this, 2, 2]
invokevirtual Calc/rpower(II)I ; this.rpower(2, 2)の呼び出し,新しいフレーム作成
local=[this, 2, 3] stack=[2, 4]
imul
local=[this, 2, 3] stack=[8]
ireturn ; スタックトップの8を呼び出し側に返す

this.rpower(2, 2)の呼び出し
local=[this, 2, 2] stack=[]
iload_2
local=[this, 2, 2] stack=[2]
ifle Label1 ; スタックトップが0以下ならLabel1にジャンプ,p.343
local=[this, 2, 2] stack=[]
iload_1
local=[this, 2, 2] stack=[2, ]
aload_0
local=[this, 2, 2] stack=[2, this]
iload_1
iload_2
local=[this, 2, 2] stack=[2, this, 2, 2]
iconst_1
local=[this, 2, 2] stack=[2, this, 2, 2, 1]
isub
local=[this, 2, 2] stack=[2, this, 2, 1]
invokevirtual Calc/rpower(II)I ; this.rpower(2, 1)の呼び出し,新しいフレーム作成
local=[this, 2, 2] stack=[2, 2]
imul
local=[this, 2, 3] stack=[4]
ireturn ; スタックトップの4を呼び出し側に返す

this.rpower(2, 1)の呼び出し
local=[this, 2, 1] stack=[]
iload_2
local=[this, 2, 1] stack=[1]
ifle Label1 ; スタックトップが0以下ならLabel1にジャンプ,p.343
local=[this, 2, 1] stack=[]
iload_1
local=[this, 2, 1] stack=[2, ]
aload_0
local=[this, 2, 1] stack=[2, this]
iload_1
iload_2
local=[this, 2, 1] stack=[2, this, 2, 1]
iconst_1
local=[this, 2, 1] stack=[2, this, 2, 1, 1]
isub
local=[this, 2, 1] stack=[2, this, 2, 0]
invokevirtual Calc/rpower(II)I ; this.rpower(2, 0)の呼び出し,新しいフレーム作成
local=[this, 2, 1] stack=[2, 1]
imul
local=[this, 2, 3] stack=[2]
ireturn ; スタックトップの2を呼び出し側に返す

this.rpower(2, 0)の呼び出し
local=[this, 2, 0] stack=[]
iload_2
local=[this, 2, 0] stack=[0]
ifle Label1 ; スタックトップが0以下ならLabel1にジャンプ,p.343
local=[this, 2, 0] stack=[]
iconst_1
local=[this, 2, 0] stack=[1]
ireturn ; スタックトップの1を呼び出し側に返す

$Id: rpower.html,v 1.3 2001-05-21 11:28:56+09 kaiya Exp kaiya $