assembly - 条件 if/else 语法
问题描述
从上一个关于将 n 最低有效位设置为 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
如果不是,那么有什么更惯用的方法呢?
解决方案
推荐阅读
- c++ - 在 Visual Studio 2019 的 linux 项目的链接器中设置静态库 (libconfig.a) 的路径
- node.js - 与 Sapper 兼容的设置,可从单个 Express/Polka 入口点为多个应用程序提供服务
- c# - 如何使用反射动态传递表名
- java - 与 ProcessBuilder 一起更改环境变量的问题
- reactjs - React-testing-library 用产生警告
- c# - 如何使用带有 OData 的 Automapper Queryable 扩展,嵌套 $select
- r - 我们如何检测在 R 中具有不同结果的观察结果?
- spring-boot - 如何在 Thymleaf 中动态设置数字类型的最大值
- java - 'org.apache.kafka.common.errors.SslAuthenticationException's; 没有可用的记录信息
- asp.net-core-webapi - 在 dotnet core web api ::ffff:127.0.0.1 中获取客户端 IP 地址