Author Topic: set carry state depending on values of two bits  (Read 11313 times)

Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
set carry state depending on values of two bits
« 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?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: set carry state depending on values of two bits
« Reply #1 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


Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
Re: set carry state depending on values of two bits
« Reply #2 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