Assembly 程序集中的复杂IF语句
我应该如何在汇编中编写这样的Assembly 程序集中的复杂IF语句,assembly,x86,conditional-statements,Assembly,X86,Conditional Statements,我应该如何在汇编中编写这样的if语句 if ((a == b AND a > c) OR c == b) { ... 平台:英特尔32位机器,NASM语法 更新 对于变量类型和值,请使用更容易理解的内容。我想整数对我来说很好。在泛型汇编中,它基本上是这样的(a在ax中,b在bx中,c在cx中): 如果没有错误位,可以简化为: cmp bx, cx jeq istrue cmp ax, bx jne nextinstr cmp ax, cx
if
语句
if ((a == b AND a > c) OR c == b) { ...
平台:英特尔32位机器,NASM语法
更新
对于变量类型和值,请使用更容易理解的内容。我想整数对我来说很好。在泛型汇编中,它基本上是这样的(
a
在ax
中,b
在bx
中,c
在cx
中):
如果没有错误位,可以简化为:
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在堆栈上传递给您(如果它们不是从别处加载的话)
a
、b
和c
的类型是什么?@DCoder我已经更新了问题!
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
}
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: