关于AT& T语法汇编中的cmp/jg,jle等 [英] Regarding cmp / jg, jle, etc in AT&T syntax assembly

查看:720
本文介绍了关于AT& T语法汇编中的cmp/jg,jle等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,每个在线资源都告诉我这样的事情:

So every single resource online tells me that something like this:

cmp %eax, %ebx
jg < something >

会跳到<某物>如果eax大于ebx.但是我还有另一段似乎与此矛盾的代码:

would jump to < something > if eax was greater than ebx. But I have another piece of code that seems to contradict this:

cmp $0x2, %eax
jg  < something>

,因为它跳转到< >当eax的值为3时.

as it jumps to < something > when eax has the value 3.

我错过了什么吗,或者如果b> a而不是a> b,则执行cmp a,b-jg吗?这是否也适用于其他跳转语句?

Am I missing something, or does cmp a, b - jg execute if b > a and not a>b? And does this apply to other jump statements as well?

推荐答案

当我们阅读

cmp $0x2, %eax
jg  < something >

我们知道所使用的汇编程序是一种反转指令操作数位置的汇编程序.这是因为Intel的语法规定目标操作数位于源操作数之前,并且很明显像$ 0x2这样的立即值永远不能成为目标!

we know the assembler used is one that reverses the position of the operands of an instruction. That's because Intel's syntax dictates that the destination operand comes before the source operand and clearly an immediate value like $0x2 can't ever be a destination!

知道了事情的顺序后,我们现在将您的第一个代码片段解释为

Knowing the order of things we now interpret your first code snippet as

cmp ebx, eax
jg < something >  ;jump if EBX > EAX

,第二个代码段为

cmp eax, 2
jg < something >  ;jump if EAX > 2

这也适用于其他跳转语句吗?

And does this apply to other jump statements as well?

可以.

这篇关于关于AT&amp; T语法汇编中的cmp/jg,jle等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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