Книга: Introduction to Microprocessors and Microcontrollers

The XOR gate

The XOR gate

This is called the Exclusive-OR gate, which is abbreviated to XOR or EOR. Here are two examples of everyday English, both using the word ‘or’.

We get into an elevator and the operator says to us ‘Do you want to go up or down?’ We have a choice, we can decide to go up or we can go down. We have two possible answers – ‘up’ or ‘down’.

On the way home we buy a burger. We are asked ‘Do you want ketchup or mustard?’ This time we could answer ‘ketchup’ or ‘mustard’ or we could say ‘both’.


Figure 5.11 The XOR or difference gate

This is a fine example of how we can make something which is really easy appear difficult. The word ‘or’ in English has two different meanings which can be referred to as exclusive and inclusive. The first example used the exclusive ‘or’ because we could have one or the other but not both. The second situation uses the inclusive ‘or’ because we could have one or the other or both. We use both meanings everyday and understand them so well that we know automatically which one is meant.

In the XOR gate the output is a logic one if either input is a logic 1 but not both. Only two-input XOR gates are manufactured, whether for use in a microprocessor or not (see Figure 5.11).

To look at it in another way, the output from an XOR is a logic one if the two inputs are different. For this reason, it is often called a ‘Difference’ gate.

The electronic padlock

When we want to take some money out of our bank account we can go to the money machine and pop our card in. It then asks us to key in our code number which is usually a four-digit number. If the number is correct, we have access to our account.

In the background is a microprocessor with two useful attributes:

1 Microprocessors are very good at spotting whether a number is zero or not.

2 They contain a series of XOR gates.

So how can it check my number? One easy method is to compare our keyed-in number with the number read from the magnetic strip on the back of the card. Each of our code numbers is treated as a hex number and converted to a four-bit binary number. This results in one 16-bit binary number from the keyboard and another from the magnetic strip on the card, which now have to be compared.

Inside the microprocessor are 16 XOR gates each with two inputs – one from the card and one from the keyboard. Every time the bits coincide, whether they are both zeros or both ones, the output will be a zero.

The 16 results are quickly scanned looking for any output which is not zero. This would indicate an incorrect number. The process is shown in Figure 5.12 but for clarity, only four of the XOR gates have been shown. In real life, there will be 16 of them, of course.


Figure 5.12 Using an XOR gate to compare numbers

The extra bit

The XOR function can be written as ?. So, if an XOR gate had inputs called A and B and an output called X, then it would be abbreviated as X=A?B.

Оглавление книги


Генерация: 0.036. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз