Thread: Emulating x86 Instructions

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK

    Emulating x86 Instructions


    I'm trying to translate some x86 assembly language into C so I can better understand what it's doing, however I can't really work out how best to deal with the "Add With Carry" (ADC) and "Subtract With Borrow" (SBB) instructions. In this code, they always come immediately after an ADD/SUB instruction performed on the next word along in memory, so I would presume that the one instruction affects the other, particularly when I'm seeing things like:-
    sub [BX+(blah + 2)], 0Ah
    sbb [BX+blah], 0
    Which to my mind, the second instruction does nothing.

    What's the C equivalent?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    They handle overflow / underflow when manipulating values which are wider than registers.

    19 +

    4 and 9 you add and the result is 3 (but there's a carry)
    1 and 1 you "add with carry" and you get 3 as well
    Hence the result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. x86 Instruction SBB
    By Aleck_pl in forum C Programming
    Replies: 6
    Last Post: 04-10-2009, 04:43 PM
  2. strange 4 assembly instructions for a function
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 07-21-2008, 02:59 AM
  3. Mixing user mode and OS instructions
    By Canadian0469 in forum C Programming
    Replies: 2
    Last Post: 11-05-2007, 03:49 AM
  4. x86 64 C data type sizes
    By valis in forum Tech Board
    Replies: 6
    Last Post: 07-25-2006, 07:17 AM
  5. x86-64 vs x86
    By Silvercord in forum Tech Board
    Replies: 10
    Last Post: 02-12-2003, 04:44 PM