Comparison - Page 2
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. think about how slow the decrement is going to be if the numbers are very large.

2. What about integer divide... test for zero?

3. Member
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. I would use Souldog's method instead of mine

5. 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.

6. Member
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. 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.

#### Posting Permissions

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