if
アセンブリでそのようなステートメントをどのように記述すればよいですか?
if ((a == b AND a > c) OR c == b) { ...
プラットフォーム: Intel 32 ビット マシン、NASM 構文。
アップデート
変数の型と値は、より理解しやすいものを使用してください。整数は私にとってはうまくいくと思います。
if
アセンブリでそのようなステートメントをどのように記述すればよいですか?
if ((a == b AND a > c) OR c == b) { ...
プラットフォーム: Intel 32 ビット マシン、NASM 構文。
アップデート
変数の型と値は、より理解しやすいものを使用してください。整数は私にとってはうまくいくと思います。
一般的なアセンブリでは、基本的に次のようになります(a
in ax
、b
in bx
、c
in cx
):
cmp bx, cx
jeq istrue
cmp ax, cx
jle isfalse
cmp ax, bx
jeq istrue
isfalse:
; do false bit
jmp nextinstr
istrue:
; do true bit
nextinstr:
; carry on
偽のビットがない場合は、次のように簡略化できます。
cmp bx, cx
jeq istrue
cmp ax, bx
jne nextinstr
cmp ax, cx
jle nextinstr
istrue:
; do true bit
nextinstr:
; carry on
ifステートメントを一連の比較とジャンプに分割する必要があります。Cの場合と同じように、次のように書くことができます。
int test = 0;
if (a == b) {
if (a > c) {
test = 1;
}
}
// assuming lazy evaluation of or:
if (!test) {
if (c == b) {
test = 1;
}
}
if (test) {
// whole condition checked out
}
これは、複雑な式を構成要素に分割しますが、asmは、まだ関連する部分にジャンプすることで、asmでよりきれいに書くことができます。
a、b、cがスタック上で渡されていると仮定します(明らかに他の場所からロードされていない場合)
mov eax, DWORD PTR [ebp+8]
cmp eax, DWORD PTR [ebp+12] ; a == b?
jne .SECOND ; if it's not then no point trying a > c
mov eax, DWORD PTR [ebp+8]
cmp eax, DWORD PTR [ebp+16] ; a > c?
jg .BODY ; if it is then it's sufficient to pass the
.SECOND:
mov eax, DWORD PTR [ebp+16]
cmp eax, DWORD PTR [ebp+12] ; second part of condition: c == b?
jne .SKIP
.BODY:
; .... do stuff here
jmp .DONE
.SKIP:
; this is your else if you have one
.DONE: