How does the TEST build instruction work with these branch instructions?

Using the AT & T assembly syntax, I am trying to understand how it is testlused in assembler. In particular:

testl  %edx, %edx
jle    .L3

I know that it testlperforms a bit-wise value of andthe same value to set the condition flags, but how can I interpret "transition if it is less than or equal to" if it does not compare two values?

+5
source share
3 answers

Here is an excerpt from Intel's official test documentation:

Operation
TEMP ← SRC1 AND SRC2;
SF ← MSB(TEMP);
IF TEMP = 0
    THEN ZF ← 1;
    ELSE ZF ← 0;
FI:
PF ← BitwiseXNOR(TEMP[0:7]);
CF ← 0;
OF ← 0;

And the same for jle:

Jump if less or equal (ZF=1 or SF≠OF)

, , edx 0 ( edx AND edx = edx 0 , edx 0, , ZF 1, AND 0), edx 1 ( SF = most significant bit of edx AND edx (, , edx) OF 0, SF ≠ OF, , SF ≠ 0).

IOW, , edx ≤ 0, , , edx 0 0x80000000 .

+9

x86 ( jcxz, jecxz, loop loopne/loopnz). , , , - , .

jle jng. ZF = 1 or SF <> OF. , Intel x86 JUMP.

test , AF , .

OF. , ZF = 1 or SF = 1, jle , edx 0 0x80000000... 0xffffffff.

+2

TESTL (, edx edx) ( x AND x x). , AND , - , , - edx.

TESTL ZF 1, . TESTL OF 0 SF, .

JLE , ZF 1 SF <> OF.

, , :

  • edx ;
  • edx .

, edx 0 0x80000000 - 0xffffffff.

Most likely, this is a check so that the number is a natural number 0x00000001 - 0x7fffffff, the transition would be to the procedure for processing errors of some kind, and the real natural number would continue without a transition, for example:

loop_for_number:
    call   get_number_into_edx
    testl  %edx, %edx
    jle    loop_for_number

    ; carry on here knowing that edx >= 1

For a description of the different jumps and the flags used by him, see here .

+2
source

All Articles