条件if / else语法

问题描述

从上一个关于Set n least significant bits to 1的问题中得到很好的答案,我编写了一个函数来确定正整数是否为2的幂:

# Is 16 a multiple of 8 (2^3)? Yes
mov $16,%edi
mov $3,%esi
call pow_2_short

pow_2_short:
    mov $1,%eax
    mov %sil,%cl # move low byte of %esi (the power of 2) into %cl for the shift
    shl %cl,%eax
    dec %rax
    test %eax,%edi
    jz _set_true; jnz _set_false
  _set_false:
    xor %eax,%eax
    ret
  _set_true:
    mov $1,%eax
    ret

我对此的主要疑问是对我来说有点奇怪的条件部分。上面的模式是基本的常用方法吗?

if x:
    // do this
else:
    // something else

如果没有,那么更惯用的方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)