2011-06-22 46 views
1

这汇编代码:大会C代码

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(); 
} 

回答

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: 
+0

我认为你有第二个错误。 –

+0

@Mike是的,我刚刚发现,当再次检查。谢谢。 –

0

不,它不是。如果variable1小于10,汇编代码将调用SomeFunction和C代码不会,它会跳转到AlternateBlock

+0

但是为什么呢;如果变量1 <10,如果高于或相等,jae不会跳转? –

+0

@Thanos:是的,所以bacause变量小于10,它不会跳到任何地方,并会转到下一个语句,这就是所谓的函数 –

+0

我的意思是说,如果JAE不是(> =)? –

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: 
+0

非常感谢。 –