1. Hey!!

I want to check using bitwise operations if x XOR y=0.

The only conditional command we have is JMN a, which means Jump to a if the currect value is <0.

So, we have to check if it doesn't hold that x XOR y <0 and x XOR y >0, right?

But how can we check the condition x XOR y >0 ?

Using the operation NOT ( x XOR y ) we don't get -(x XOR y) right?

2. Originally Posted by mathmari
I want to check using bitwise operations if x XOR y=0.
What do you mean by checking? What are x and y?

Originally Posted by mathmari
The only conditional command we have is JMN a, which means Jump to a if the currect value is <0.
And literally no single other command?

3. Originally Posted by mathmari

Using the operation NOT ( x XOR y ) we don't get -(x XOR y) right?
-(x XOR y) ? Do you mean $\lnot(x \ XOR \ y)$ ?

x XOR y will be 0 when either x or y is 1 but not both. You can see a truth table for this.

Evgeny makes a good point by asking what x and y are. Unless you are using some sort of thresholding operation, typically bitwise operations will have solutions of either true or false, 1 or 0, not 'greater than 0' or 'less than 0'.

Maybe you want to use some other variables to test the x XOR y condition, and then assign something to a data type that can handle the '> 0' part?

Originally Posted by Joppy
x XOR y will be 0 when either x or y is 1 but not both. You can see a truth table for this.
XOR checks if each bit of the two values is the same, or not?
I mean that if one bit is the same the result is 0, and if not the result is 1, right?

For example, we have that
1100 XOR 1010 = 0110
. So, only if the result is 0 we have that the two numbers are the same, right?

It holds that $x-y=0$ if it doesn't hold that $x-y<0$ and neither $x-y>0 \Rightarrow -(x-y)<0$.

I implemented now the command NEG, that computes the negation of a constant.

It holds that $x+ \sim x+1=0$. Therefore it holds that $-x= \sim x +1$.
($\sim x$ is the bitwise negation of $x$)

So, for two constants $x$ and $y$, we want to check if $x \ XOR \ y=0$.

1) We compute the
x XOR y

2) If the result is negative (JMN) then go to step 6
3) We compute the negation of the above result
4) If this is negative (JMN) then go to step 6
5) It holds that $x \ XOR \ y=0$ and so $x=y$
6) It holds that $x \ XOR \ y\neq 0$ and so $x\neq y$

Is everything correct?

5. Originally Posted by mathmari
XOR checks if each bit of the two values is the same, or not?

I mean that if one bit is the same the result is 0, and if not the result is 1, right?
It's just an operator. But i guess we can say it 'checks'. If two of the bits are the same, then the result is false. For all other cases, the result is true.

Quote:
For example, we have that
1100 XOR 1010 = 0110
. So, only if the result is 0 we have that the two numbers are the same, right?
Hmm. No? $1100 \ne 1010$ in base 10 and base 2. I see what you are trying to do though.. Can't we just,

Or something along those lines

I feel like you might be applying the rules and conditions of ordinary algebra to that of Boolean algebra. Changing the data type wherever it suits, so I don't really understand. I will leave it for someone more knowledgeable in the area to chime in .

6. My two cents as someone who is pretty rusty in assembly language: I think the answer depends entirely on the instruction set of your assembly language, and depending on the commands thereof, there may be multiple ways of tackling this problem. Some assembly languages also have special registers that have particular functions which can simplify code.

I think an important question to ask is which assembly language /processor you are using and which commands are available to you. The processor I used in the past had an operation XOR that would perform bitwise exclusive-or on two binary variables, and if resulted in 0, would toggle a certain bit on a register. All that was left to do was to check if that bit was set or not, and then branch from there. Sometimes you may be able to do this task directly if you have a "comparison" operator followed by a jump instruction.

For example:

CMP X, Y
JMN LESSTHAN
GREATERTHAN:
;do something
LESSTHAN:
;do something

If I recall correctly, the compare operator does perform some sort of subtraction, so the logic basically reduces to what Joppy has said. If you don't have a CMP operator, you may be able to use a SUB operator instead.