Assembly JLE jmp instruction example

落花浮王杯 提交于 2019-11-30 14:51:32

问题


How do you use the jump family of instructions?

This is what they've got:

JL label
"It" jumps if it is less than or if it is not larger than or equal to.

My question is what is it in this sentence? Say I have a variable in ebx and I want to jump to label there: if ebx is <= 10.

Specifically I'm interested in using the x86 jump family of instructions


回答1:


The jump itself checks the flags in the EFL register. These are usually set with TEST or CMP(or as a side effect of many other instructions).

CMP ebx,10
JLE there
  • CMP corresponds to calculating the difference of the operands, updating the flags and discarding the result. Typically used for greater/smaller checks
  • TEST corresponds to calculating the binary AND of the operands, updating the flags and discarding the result. Typically used for equality checks.

See also: The art of assembly language on CMP

As a sidenote: You should get the Intel reference manuals. In particular the two part "Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 2: Instruction Set Reference" which describes all x86 instructions.




回答2:


JLE instruction actually tests two flags at once:

  • Zero Flag (ZF)
  • Carry flag (CF)

If Carry and Zero flags are 1 then the short relative jump will be executed.

Maybe just a word how CMP instruction works. CMP instruction is like SUB (subtract), but the destination register will not be updated after exsecution. So the following code will perform the same result like CMP ebx, 10. CMP and SUB instruction affect to flags: Carry, Parity, Auxiliary, Zero, Sign and Overflow flags.

push   ebx            //store ebx value to stack
sub    ebx, 10
pop    ebx            //restore ebx value from stack



回答3:


The x86 assembly uses a system of bit-flags that represent the result of comparisons. The conditional jump instructions use these flags when deciding whether to perform the jump or not.

In your case you'd use the following two instructions:

cmp ebx, 10     ; compare EBX and 10
jle label       ; jump if the previous comparison is "less than or equal"
…
label:
…



回答4:


JB - work with unsigned numbers (Jump Below) <

JL - work with signed numbers

mov bx,0     // BX := 0
cmp bx,FF    // 0 < -1 or 0 < 255 (Jump Flag and Sign Flag will change)
jl  butter   // if you use JL jump will not occurs, cus 0 > -1
jb  butter   // if you use JB jump will occurs, cus 0 < 255


来源:https://stackoverflow.com/questions/4557279/assembly-jle-jmp-instruction-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!