jle汇编_关于AT& T语法汇编中的cmp / jg,jle等

本文探讨了在AT&T汇编语法中cmp指令与jg等跳转指令的使用。通常cmp %eax, %ebx后,jg会在eax大于ebx时跳转,但示例代码中当eax为3时,cmp $0x2, %eax jg也会跳转,这引发了疑问。实际上,这是由于AT&T语法中操作数位置的反转,正确的理解应为cmp eax, 2,即在eax大于2时跳转。这种现象同样适用于其他跳转指令。" 132062829,7329715,使用Arduino驱动MG-811 CO2传感器教程,"['Arduino', '传感器驱动', '气体传感器', 'CO2检测', '电子制作']
摘要由CSDN通过智能技术生成

bd96500e110b49cbb3cd949968f18be7.png

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

cmp %eax, %ebx

jg < something >

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>

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

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?

解决方案

When we read something like

cmp $0x2, %eax

jg < something >

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

and the second code snippet as

cmp eax, 2

jg < something > ;jump if EAX > 2

And does this apply to other jump statements as well?

It does.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值