此汇编代码:
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();
}
最佳答案
更简洁:
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:
关于c - 汇编成 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6441605/