Working on logic design in class, and I'm trying to figure out how to write a specific logic function [and by write, I mean something along the lines of (x NOR y) OR (a NOR b), for example]
It asks to assume 2 variables, X and Y, both of which consist of 3 bits (x2,x1,x0, and y2,y1,y0). I need to write a logic function that is true if and only if X < Y, assuming that they are signed 2's complement numbers.
I have somewhat of an idea of how to form a logic circuit that accomplishes this by subtracting and checking if the result is negative, which would use full-adders to add X to Y's inverse plus 1. I'm just struggling to figure out how to actually write that down in the form I stated above.
Edit: I really wasn't able to wrap my head around how to write this down as a function, so I went and made an adder/subtractor using a logic gate simulator:
and I worked up from bit 0, piecing together each logic equation:
Bit 0's sum is:
(x0 XOR y0') XOR (Cin0)
Bit 0's carry out is:
(Sum w/o carry-in) XOR (x0 AND y0')
Which is the same as:
((x0 XOR y0') AND (Cin0)) OR (x0 AND y0')
That then becomes the carry-in (Cin) of bit 1:
((x1 XOR y1') AND (((x0 XOR y0') AND (Cin0)) OR (x0 AND y0'))) OR (x1 AND y1'))
Then finally, for bit 2 (the sign bit), I dropped the carry out, plugging in bit 1's carry out to bit 2's carry in:
(x2 XOR y2') XOR (((x1 XOR y1') AND (((x0 XOR y0') AND (Cin0)) OR (x0 AND y0'))) OR (x1 AND y1'))
The first carry-in, Cin0, is 1 for the purpose of converting from a signed 2s complement number. Then the function just checks whether or not the sign bit is on or off, b/c if x - y is negative, then x < y.
I did x = -1 and y = 3 for an example (in 2s complement, those are 111 and 011 respectively)
I feel like this is all really, really convoluted though, and I can't help but wonder if I've messed up somewhere along the way, or if I'm overthinking this. I just can't visualize how the logic works without... well, visuals.