Logic function for $c=a-b$ where $a,b \in [0,31]$.

30 Views Asked by At

I need to create a switching function that performs the subtraction $c=a-b$ where $a,b \in [0,31]$.

Now, my workbook has realized $c=a+b, a,b \in [0,15]$ using two functions (each with three arguments). The first function is $c_i = \sum(a_i, b_i, p_{i-1})$, which calculates the sum of two bits (the third parameter is carry). The second function functions similarly, by calculating the carry bit, if its given three bits ($a_i, b_i, p_{i-1})$ as input.

The truth table of those functions looks like this:

enter image description here

We now have recursive formulae: $c_i = a_i \oplus b_i \oplus p_{i-1}$, similarly for $p_i$.

Now, could someone give me an idea how to do this? I tried using the same function but with $\neg b_i$, since I thought of adding the two's complement of $b_i$ to $a_i$, but I also need to add $1$ to $b_i$ after inverting all the bits. Can anyone help?