为什么逻辑“不"?汇编中if语句中的条件? [英] why logical"NOT" the condition in if statement in assembly?

查看:78
本文介绍了为什么逻辑“不"?汇编中if语句中的条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习程序集,一本教科书显示了条件控制的示例:

我不明白为什么在第3行中使用 x> = y ,为什么不仅仅遵循逻辑并使用 x< y (与原始C代码相同))?(不是)if语句中的条件有什么特殊原因吗?

解决方案

if()语句的意思是如果条件不成立,则跳过此步骤".

如果条件为true,则希望执行插入到 if 主体中;如果条件为false,则希望执行跳过 if 主体./p>

因此,编译 if 的显而易见的/文字方式是在相反条件下使用jcc,例如 jnl .(对于那些高度相关的if/else块,例如减法和条件求反,优化的代码当然可以做得更好.)

如果您想使用 jl ,则必须将 if -body放在行外,也许在 ret 之后函数的末尾,然后从中跳回.

I'm learning assembly and a textbook shows an example of condition control:

I don't understand why x>=y is used in line 3, why not just follow the logic and use x<y (same as original C code)? is any particular reason to !(not) the condition in if statement?

解决方案

An if() statement means "skip this if the condition is not true".

If the condition is true, you want execution to fall-through into the if body, and if it's false you want execution to jump over the if body.

Thus, the obvious / literal way to compile an if is with a jcc on the inverse condition, like jnl. (Optimized code could certainly do much better for those highly-related if/else blocks, like subtract and conditional negate.)

If you wanted to use jl, you have to put the if-body out-of-line, maybe after the ret at the end of the function, and then jump back from it.

这篇关于为什么逻辑“不"?汇编中if语句中的条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆