NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: mik3ca on February 08, 2021, 12:25:37 AM

Title: set carry state depending on values of two bits
Post by: mik3ca on February 08, 2021, 12:25:37 AM
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: [Select]
comparefunction:
    cmp AX,BX
    je ok
      stc
      ret
    ok:
    clc
 ret

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: [Select]
    sub AX,BX

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?
Title: Re: set carry state depending on values of two bits
Post by: Frank Kotler on February 08, 2021, 02:08:37 AM
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

Title: Re: set carry state depending on values of two bits
Post by: mik3ca on February 08, 2021, 08:37:36 PM
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