Trick with SBB instruction

spamtrap_at_crayne.org
Date: 01/10/05

  • Next message: Swen Kuehnlein : "movaps / movapd"
    Date: Mon, 10 Jan 2005 19:00:15 +0000 (UTC)
    
    

    I have seen some (uncommented) Intel assembler code that
    frequently uses the following pair of lines:

    sbb eax,eax
    sbb eax,0FFFFFFFFh

    and I was wondering what this is intended to achieve.

    Some Googling on 'sbb' indicates that the first is a
    well-known trick for setting eax to 0 if the carry flag
    is not set and to 0FFFFFFFFh otherwise.

    But it isn't immediately obvious what the second instruction
    then adds to the construction.

    It would help if I was convinced that the following two
    register operations were identical for all operand values:

    reg1 = (reg1 - reg2) - carry

    or

    reg1 = reg1 - (reg2 + carry)

    and if not, which one is the way "sbb reg1,reg2" does things?
    Cheers

    John Ramsden


  • Next message: Swen Kuehnlein : "movaps / movapd"