简体   繁体   English

jmp和ja有什么区别?

[英]What is the difference between jmp and ja?

From my understanding jmp does an unconditional jump, whereas ja jumps if the value is unsigned. 根据我的理解, jmp执行无条件跳转,而ja跳转,如果值是无符号的。 Am I getting this right? 我说得对吗?

An example would be greatly appreciated. 一个例子将不胜感激。

You're correct that jmp does an unconditional jump. 你是正确的, jmp无条件跳转。

Your description of ja is incorrect, though. 但是,您对ja描述不正确。 It does a conditional jump, based on the result of the most recent cmp operation. 它根据最近的cmp操作的结果进行条件跳转。 It jumps if the first operand was greater than the second operand, using unsigned comparison rather than signed comparison. 如果第一个操作数大于第二个操作数,则跳转,使用无符号比较而不是签名比较。 jg would use signed comparison. jg将使用签名比较。

ja means "jump if Carry Flag unset and Zero Flag unset". ja表示“如果进位标志未设置且零标志未设置则跳转”。

The cmp instruction is really the same as the sub instruction (ie it subtracts its arguments), except that the result is not saved but only the condition flags are updated. cmp指令实际上与sub指令相同(即它减去其参数),除了不保存结果但只更新条件标志。

If we were comparing unsigned integers, subtracting (ab) sets the Carry Flag if b is greater than a , and the Zero Flag if b is equal to a , so if neither of these flags is set, it follows that a is greater than b . 如果我们比较无符号整数,如果b大于a ,则减去(ab)设置进位标志,如果b等于a ,则减去零标志,所以如果这两个标志都没有设置,则a大于b

If we wanted a comparison of signed numbers, we'd have to compare the Sign Flag (ie the topmost bit of the result) to the Overflow Flag, and check that the Zero Flag is unset, which is what the jg instruction does. 如果我们想要对有符号数进行比较,我们必须将符号标志(即结果的最高位)与溢出标志进行比较,并检查零标志是否未设置,这是jg指令的作用。

Thus, the cmp instruction does not care about whether the arguments are signed or unsigned. 因此, cmp指令不关心参数是有符号还是无符号。 This distinction is only in how the flags are interpreted afterwards. 这种区别仅在于如何在之后解释标志。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM