HOME       UP       PREV       NEXT (Long Multiplication)  

Subtractor, Equality, Inequality, Shifts

Using negation and swapping, all of these operators boil down to just two (addition and equality): + - < > ?= <= != == << >> .

Subtractor: use an adder but instead pass in a one as the leading borrow-bar and complement each bit from the second operand.

A subtractor will generate a borrow output. If a < b then a-b will need a borrow, hence the raw subtractor implements less-than.

Greater than or equal is just the complement of less than.

For the other two inequalities: just swap the operands.

Equality test: one could use a subtractor and check the output is zero, but it's simpler to use a dijunction of XORs (i.e. we don't need to consider carry operations).


(C) 2008-10, DJ Greaves, University of Cambridge, Computer Laboratory.