Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly JLE jmp instruction example

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

like image 599
bobobobo Avatar asked Dec 29 '10 19:12

bobobobo


People also ask

What does JLE do in assembly?

The jle instruction is a conditional jump that follows a test. It performs a signed comparison jump after a cmp if the destination operand is less than or equal to the source operand.

How does jmp work in assembly?

In the x86 assembly language, the JMP instruction performs an unconditional jump. Such an instruction transfers the flow of execution by changing the program counter.

What is jump instruction in assembly language?

A jump instruction, like "jmp", just switches the CPU to executing a different piece of code. It's the assembly equivalent of "goto", but unlike goto, jumps are notconsidered shameful in assembly.

What does JNE mean in assembly?

je" (jump if equal) and "jne" (jump if not equal) are just aliases of jz & jnz, because if the difference is zero, then the two values are equal.


2 Answers

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.

like image 100
CodesInChaos Avatar answered Oct 14 '22 10:10

CodesInChaos


JLE instruction conducts two tests:

  • Signed Flag (SF) != Overflow Flag (OF)
  • Zero flag (ZF) == 1

If Zero flags is 1 and Signed Flag and Overflow Flag are not equal, 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
like image 37
GJ. Avatar answered Oct 14 '22 12:10

GJ.