I have a 16 bit binary number $x$, and I want to perform on it a series of operations that will result in: if $x = 0000000000000000$ then $f(x) = 1111111111111111$, and if $x \neq 0000000000000000$, then $f(x) = 0000000000000000$.
Here are the operations I have ($y$ is any 16-bit number) :
- Binary 16-bit addition $(x+y)$, that ignores overflow beyond the 16-bit.
- Binary 16-bit subtraction
- Bitwise 16-bit AND $(x\;\&\;y)$: for example $1111111111111111\;\&\; 1111111111111000 = 1111111111111000$
- Bitwise 16-bit OR
- Bitwise 16-bit NOT $(!x)$, for example $!(1111111111111000) = 0000000000000111$
These restraints are because those are the operations my ALU supports. Even If you have a function that requires more than the above operations, please share it, and I will figure out how to do it.
Thanks
As a first step, here is a function
is0(x)that returns1000000000000000if x is zero and0if x is non-zero.This is independent of any carry in the ALU, and already gives a non-zero result if x=0 and a zero otherwise.
Now the final tricky function
iszero(x)that uses carry arithmeticThe function was implemented and fully tested on a x86 system, here the code with Intel syntax