此汇编代码:
cmp [Variable1], 10
jae AlternateBlock
call SomeFunction
jmp AfterIfBlock
cmp [Variable1], 345
jne AfterIfBlock
call SomeOtherFunction
等于这个C代码?:
if (variable1 >= 10)
{
goto AlternateBlock;
SomeFunction();
goto AfterIfBlock;
}
else if (Variable1 != 345)
{
goto AfterIfBlock;
SomeOtherFunction();
}
答案 0 :(得分:5)
更简洁:
if( variable1 < 10 ) {
SomeFunction();
} else if( variable1 == 345 ) {
SomeOtherFunction()
}
说明:
cmp [Variable1], 10
jae AlternateBlock ; if variable1 is >= 10 then go to alternate block
call SomeFunction ; else fall through and call SomeFunction(). ie. when variable1 < 10
jmp AfterIfBlock ; prevent falling through to next conditional
cmp [Variable1], 345
jne AfterIfBlock ; if variable1 is not equal to 345 then jump to afterifblock
call SomeOtherFunction ; else fall through to call SomeOtherFunction
如果您需要一些时间来理解它,您应该看到它在语义上等同于C代码。也许这有帮助。
cmp [Variable1], 10
jb @f
call SomeFunction
jmp end
@@:
cmp [Variable1], 345
jnz end
call SomeOtherFunction
end:
答案 1 :(得分:4)
不,它可能更像是这样:
if (variable1 < 10)
SomeFunction();
else if (Variable1 == 345)
SomeOtherFunction();
但是你没有在汇编程序中包含标签,所以我不能确定。我认为标签是这样的:
cmp [Variable1], 10
jae AlternateBlock
call SomeFunction
jmp AfterIfBlock
@@AlternateBlock:
cmp [Variable1], 345
jne AfterIfBlock
call SomeOtherFunction
@@AfterIfBlock:
答案 2 :(得分:0)
不,不是。如果variable1
小于10,汇编代码将调用SomeFunction
,而C代码则不会,它将跳转到AlternateBlock