tags:

views:

204

answers:

3

how do you decide when do you use which jump statement...statements such as JG JNLE JNC can do the same job how do u diffrentiate them?

+4  A: 

Some mnemonics are just referring same instruction. If you are interested if result of comparison use jG JGE etc. If you are interested in CPU flags set use JC, JZ etc. It'll just increase readability of code

drlazy
+4  A: 

The jumps you mention are all jumps on condition code values.

JG and JNLE are the same: they have the same opcode and do the same thing. One is "jump if greater than", and the other is "jump if not less than or equal to". Think about it. These are signed branches, that means they take the sign flag into account when determining whether to branch.

JNC means "jump if no carry". It will jump if the carry flag is not set. Carry is often used to detect arithmetic overflow, for example when adding 2 unsigned integers.

Richard Pennington
+2  A: 

J(E)CXZ is used generally when you've got a count value in the CX register that you're using to limit iterations in loops.

JMP is an unconditional jump used to exit loops, enter APIs in a non-CALL based interface, build jump tables, etc.

Conditional jumps are used to change your thread of execution based upon conditions of previous calculations. There are a lot of synonyms (documented in the link I just provided) and the synonyms are usually for obvious reasons. JAE, for example, means "Jump if Above or Equal". This is a synonym for JNC, which means "Jump if No Carry" and JNB, which means "Jump if Not Below". Which you use is purely a matter of making your code understandable to the reader:

  • If you've just done an arithmetic operation, you're likely to be interested in the state of the carry flag, so you'd code it as JNC.
  • If you've just done a comparison (CMP operation) you'll likely to be more interested in JAE or JNB. Which you use depends on which makes the most sense when describing the logic.

This is actually a classic problem in language design: do you make lots of aliases, making the syntax more complicated in favour of clarifying semantics, or do you restrict your "keywords" (opcode mnemonics here) at the expense of semantics being harder to read?

JUST MY correct OPINION