Comparison - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: Comparison

  1. #16
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    think about how slow the decrement is going to be if the numbers are very large.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  2. #17
    Join Date
    Sep 2002
    Posts
    1,747
    What about integer divide... test for zero?
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  3. #18
    Join Date
    Jun 2003
    Location
    India
    Posts
    118
    Thanx, Souldog & TheRogue

    Really thanx,, i will work on your solutions. and come back to you if any problems.


    regards,
    -Piyu

  4. #19
    Join Date
    Mar 2002
    Location
    Kent, United Kingdom
    Posts
    399
    I would use Souldog's method instead of mine
    your humble savant

  5. #20
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Well I went and looked this up.

    2.2.1 Comparisons
    Control structures decide what to do based on comparisons of data. In
    assembly, the result of a comparison is stored in the FLAGS register to be
    used later. The 80x86 provides the CMP instruction to perform comparisons.
    The FLAGS register is set based on the di erence of the two operands of
    the CMP instruction. The operands are subtracted and the FLAGS are set
    based on the result, but the result is not stored anywhere. If you need the
    result use the SUB instead of the CMP instruction.
    For unsigned integers, there are two flags (bits in the FLAGS register)
    that are important: the zero (ZF) and carry (CF) flags. The zero flag is
    set (1) if the resulting di erence would be zero. The carry flag is used as a
    borrow flag for subtraction. Consider a comparison like:
    cmp vleft, vright
    The difference of vleft - vright is computed and the flags are set accordingly.
    If the difference of the of CMP is zero, vleft = vright, then ZF is set
    (i.e. 1) and the CF is unset (i.e. 0). If vleft > vright, then ZF is unset
    and CF is unset (no borrow). If vleft < vright, then ZF is unset and CF
    is set (borrow).
    For signed integers, there are three flags that are important: the zero
    (ZF) flag, the overflow (OF) flag and the sign (SF) flag. The overflow flag is set if the result of an operation overflows (or underflows). The sign flag
    is set if the result of an operation is negative. If vleft = vright, the ZF
    is set (just as for unsigned integers). If vleft > vright, ZF is unset and
    SF = OF. If vleft < vright, ZF is unset and SF 6= OF.
    Do not forget that other instructions can also change the FLAGS register,
    not just CMP.
    Just for your info. I know you have a different processor, but
    something similar must be there
    Last edited by souldog; December 12th, 2003 at 06:30 AM.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  6. #21
    Join Date
    Jun 2003
    Location
    India
    Posts
    118
    Thanx Souldog,

    The method using decrementing variable is really slow.. but it works..

    any way i want to go though your suggestion...

    thanx for providing the information.

    regards,
    -Piyu

  7. #22
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Originally posted by PiyuNewe
    I want to write an assembly language code for one specific microprocessor which doesn't contain any cmp ('compare' ), jl('jump if less'), jg (jump if greater) instructions. so i am thinking how it is possible to find greatest number out of A and B.
    That must be a brutally performant processor

    Substract the numbers and look at the sign bit.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center