c - 汇编成 C 代码

标签 c assembly

此汇编代码:

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/

相关文章:

assembly - 使用 mips 汇编语言计算整数中的 1(没有任何控制指令流)

debugging - 用于 32 位 x86 汇编的 DOS 调试程序

c++ - 应用程序认为它在我的主文件夹中 OSX

c - 假设线程的执行顺序 - 陷阱和更正

c - 查找较大字符串中子字符串的位置

c - 用 C 构建一个非常简单的解析器

c++ - 调用x64汇编函数后C++变量重置为0

c++ - 我可以通过编程推断出 C++ dll 使用的调用约定吗?

c++ - 由于为 C++ 程序调用 ulldiv.asm 而导致编译器引用错误

c - 从 cstring 中删除空字符