Created
March 20, 2017 01:20
-
-
Save mirichi/bafb7b4650c664374cce9dd9f73a33f8 to your computer and use it in GitHub Desktop.
WebAssembly逆アセンブルして調べるテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/1984weed/webassembly-sample/blob/master/src/nqueen/nqueens.cの一部を逆アセンブルして調べてみた | |
int mypow(int v, int n){ | |
int res = v; | |
for (int i = 1; i < n; i++){ | |
res *= v; | |
} | |
return res; | |
} | |
--- | |
block i32 | |
get_local @1 ; 引数nをpush | |
i32.const 1 ; 1をpush | |
i32.gt_s ; op1 > op2(signed) (n > 1のこと) | |
if empty ; nが1より大きければブロックに入る | |
i32.const 1 ; 1をpush | |
set_local @3 ; @3に1をセット(iのこと?) | |
get_local @0 ; vをpush | |
set_local @2 ; @2にvをセット(変数resのこと?) | |
loop empty ; ループ用ラベル | |
get_local @2 ; @2からpush(res) | |
get_local @0 ; @0からpush(v) | |
i32.mul ; 掛け算 | |
set_local @2 ; @2に保存(res) | |
get_local @3 ; @3からpush(i) | |
i32.const 1 ; 1をpush | |
i32.add ; 加算 | |
tee_local @3 ; スタックに残したまま@3にセット(ここまで4命令でi++) | |
get_local @1 ; @1をpush | |
i32.ne ; op1 != op2 | |
br_if 0 ; loopに戻る(0は直近のブロックの意味) | |
get_local @2 ;resから取り出す | |
set_local @0 ;@0に格納する(たぶん@0を戻り値として使うため?) | |
end | |
end | |
get_local @0 ; @0をpushする(戻り値) | |
end ; blockの終わり | |
end ; 関数bodyの終わり(いるのか?FunctionBodyのフォーマットにあるから追加で出てるけど。) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment