# Design the basic comparison instructions using only bit instructions

#### Zmukbel

Hello, I need you to help me solving this question, please:

#### oneye14

This appears to be test for those of us who can count in binary but can implement an example logically;
and maybe start off from a blank sheet of paper which is how we used to commence software in the 1980's.

Firstly create 4 ladder rungs, each with 2 contacts from I0 and I1. Each o/p is the numerical value of 'A' starting at A0, through A1, A2 and A3; the contacts would be arranged in order to count upwards in subsequent rungs. Repeat with 4 more rungs 'weighting' B with similar values on flags B0, B1, B2 and B3.

The next rung energises when A=B:
A0 and B0 gives Equals o/p
or A1 and B1 Equals and so on to {A3 and B3}.

The next 2 rungs are for A>B and A<B which are slightly more complicated mindful this is very simple logic.

Expanding to four digits for A and B means you would be counting from A0 - A7 and B0 to B7 with more and larger rungs; easy once you have done it !

#### GMcc

You only need to do bit comparison, not conventional number comparison. This can all be done in three rungs. XIO and XIC most significant bits to work out which is greater, if they match then look at the next bit.

#### oneye14

The above would work for A=B only.
How would you surmise A>B and A<B ?

#### GMcc

The above works for > and <, 5 contacts in each rung, one parallel branch. To work out = you could just use XIO > and < bits or work it out separately XIO XIO and XIC XIC in parallel, 8 contacts, 2 parallel branches. I can post solution but didn’t want to complete someone’s homework, just point them in the general direction.

#### oneye14

OK I've managed to work out the solution without using intermediate flags, which is not too difficult for 2bit binary numbers; mindful the above description is hard to comprehend.

However for 4bit binary numbers and higher (8bit), intermediate flag usage as I asserted above is more practical.
It has always been my philosophy that software should be kept relatively straightforward, for after you have gone someone else has to try and comprehend what you have done.

#### GMcc

Software for projects should be kept relatively straight forward and well documented. For this text book question I am just trying to help someone solve a problem, not provide a comprehensive solution.
This problem can be solved by converting everything to a base 10 number system as suggested above or use a base 2 number system as I thought was implied by the question, working comparisons from Most Significant Bit to Least. If you want to take it another step you can simplify the logic as much as possible by using a Karnaugh map to solve.