Menu

branch problems

habran
2013-03-24
2013-04-20
  • habran

    habran - 2013-03-24

    Hi Japheth
    can you please explain why is 

    .if ( < eax) compiled to:
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA jae         0000000140055017

    and 
    .if (.AXLINEDATA.nLineBreak < eax)compiled to:
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA jge         0000000140055017

    I have bug in my program because of it

    regards

     
  • habran

    habran - 2013-03-24

    jae is good
    jge is bad

     
  • japheth

    japheth - 2013-03-24

    > can you please explain why is

    No - you haven't supplied the declaration of AXLINEDATA. But I guess the difference is due to how member nLineBreak is defined - signed or unsigned.

     
  • habran

    habran - 2013-03-24

    AXLINEDATA struct
    next               INT_PTR ?
    prev               INT_PTR ?
    wpLine       INT_PTR ?
    nLineLen      SDWORD ?
    nLineBreak    BYTE ?
    nLineFlags     BYTE ?
    nReserved    WORD ?
    nLineWidth    SDWORD ?
    nSelStart      SDWORD ?
    nSelEnd      SDWORD ?
    AXLINEDATA ends

     
  • habran

    habran - 2013-03-24

    anyway
    why is   considered as signed?
    and .AXLINEDATA.nLineBreak as usigned

     
  • habran

    habran - 2013-03-24

    sorry it is not .AXLINEDATA.nLineBreak in question
    but .AXLINEDATA.nLineWidth
    however it is translated in to :
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA  jge         0000000140055017

     
  • japheth

    japheth - 2013-03-24

    > however it is translated in to
    >: 0000000140054BA7 cmp dword ptr ,eax
    >  0000000140054BAA jge 0000000140055017

    I don't see the problem. "jae" is generated if unsigned values are compared, and "jge" is generated if signed values are compared. Since nLineWidth is signed, all looks ok. Am I missing something?

     
  • habran

    habran - 2013-03-24

    yes, have look again I tried it again and still the same resoult
         mov eax, DWORD PTR dwMaxWidth
        .if (.AXLINEDATA.nLineWidth < eax)

    0000000140054BA4  mov         eax,dword ptr 
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA  jge         0000000140054F40

    I tried with mov eax, SDWORD PTR dwMaxWidth
    with .if (SDWORD PTR.AXLINEDATA.nLineWidth < SDWORD PTR eax)

    and still the same

    only
    .if ( < eax) is compiled to:
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA  jae         0000000140055017

     
  • habran

    habran - 2013-03-24

    my question is why is .if ( < eax)
    compiled to jae
    how did compiler make decision that it is jae and not jge when there is nothing telling it about SIGNED or NOT?

     
  • japheth

    japheth - 2013-03-24

    I'd say you are confused. If you want an unsigned comparison, you'll have to write:

    .if DWORD PTR .AXLINEDATA.nLineWidth < eax

    if there's no typecast ("DWORD PTR"), the comparison will be signed.

    Just write a 32-bit version and test it with Masm, you'll see that it behaves equally.

     
  • habran

    habran - 2013-03-24

    you were right, with:
      mov eax, DWORD PTR dwMaxWidth
        .if (DWORD PTR.AXLINEDATA.nLineWidth < eax)
    I have finally got it
    0000000140054BA7  cmp         dword ptr ,eax
    0000000140054BAA  jae         0000000140054F40

    however, why SDWORD PTR doesn't give the same result?

     
  • habran

    habran - 2013-03-24

    IMO it would be more logical that SDWORD PTR create signed and DWORD PTR unsigned
    however, thank you Japheth for solving the mistery

     
  • japheth

    japheth - 2013-03-24

    > IMO it would be more logical that SDWORD PTR create signed and DWORD PTR unsigned

    Yes …. that's what they actually DO!

    >  however, thank you Japheth for solving the mistery

    You're welcome! However, there's no mystery .  take a break, and then review the Intel manuals, JCC instruction!

     
  • habran

    habran - 2013-03-24

    sorry to bother you
    I don't know why I thought that jge is unsigned and jae unsigned
    actually, I know: my IGNORANCE
    I rarely use  cmp because I like C stile .if

     

Log in to post a comment.