NASM Forum > Programming with NASM

set carry state depending on values of two bits

(1/1)

mik3ca:
I'm trying to make it so that two values are compared.
If the values are equal then the carry flag should be set to one state
If the values are not equal, then the carry flag should be in the opposite state.
I don't care if the original values are destroyed after checking for equality.

This code is an example of what I want to achieve. It sets carry if values of AX and BX are different, or it clears carry if they are equal:


--- Code: ---comparefunction:
    cmp AX,BX
    je ok
      stc
      ret
    ok:
    clc
 ret

--- End code ---

I also want to work with 32-bit values as well.

The closest thing that comes to mind which wont work with every number is this:


--- Code: ---    sub AX,BX

--- End code ---

This is because I'll get a carry bit if AX is less than BX.


Is there a simple 1-liner command that can replace the code way up above that will work for my needs?

Frank Kotler:
If the values are equal, the carry flag should already be clear, no?
I wonder why you need the carry flag. Can you operate based on the zero flag?.
(the code you show is no big deal - we're going pretty fast!)

Best,
Frank

mik3ca:
I could but given that half the time I have bad luck of the emulator box crashing sometimes (mostly due to me writing to wrong addresses), I'll stick with carry for now. but thanks

Navigation

[0] Message Index

Go to full version