Emulating x86 Instructions

This is a discussion on Emulating x86 Instructions within the C Programming forums, part of the General Programming Boards category; Hello, I'm trying to translate some x86 assembly language into C so I can better understand what it's doing, however ...

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

    Emulating x86 Instructions

    Hello,

    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:-
    Code:
    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
    Location
    The edge of the known universe
    Posts
    32,830
    They handle overflow / underflow when manipulating values which are wider than registers.

    14
    19 +
    33

    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, 05:43 PM
  2. strange 4 assembly instructions for a function
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 07-21-2008, 03: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, 08:17 AM
  5. x86-64 vs x86
    By Silvercord in forum Tech Board
    Replies: 10
    Last Post: 02-12-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21