The difference in statements about jumps in assembly programming

How do you decide when you use which branch operator ... statements like JG JNLE JNC can do the same job, how do you distinguish between them?

+4
source share
3 answers

J (E) CXZ is usually used when you have the count value in the CX register, which you use to limit iteration in loops.

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

Conditional jumps are used to change the execution flow based on the conditions of previous calculations. There are many synonyms (described in the link I just provided), and synonyms are usually for obvious reasons. For example, JAE means "Jump if higher or equal." It is synonymous with JNC, which means "Jump if No Carry" and JNB, which means "Jump if not lower." Which you use is just a question for the reader to understand your code:

  • If you have just performed an arithmetic operation, you will most likely be interested in the status of the carry flag, so you would name it as JNC.
  • If you just made a comparison (CMP operation), you will most likely be more interested in JAE or JNB. What you use depends on what makes the most sense in describing the logic.

This is actually a classic problem in language design: do you make a lot of aliases, making the syntax more complicated in favor of refining semantics, or limiting your β€œkeywords” (here option code mnemonics) is it more difficult to read due to semantics?

+4
source

The statement you mentioned is all jumping to the condition code values.

JG and JNLE are the same: they have the same opcode and do the same. One is to jump if more, and the other is to jump if not less or equal. I'm thinking about it. They are signed branches, which means that they accept the sign flag at the time of determining whether to separate it.

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

+5
source

Some mnemonics simply refer to the same instruction. If you are wondering if the comparison result uses jG JGE etc. If you are interested in CPU flags, use JC, JZ, etc. This will simply increase code readability.

+4
source

Source: https://habr.com/ru/post/1302731/


All Articles