Logic
This AND that, this OR that, EITHER this OR that, NOT this.

Cafe Assembly

Since a few of the past lessons have been on boring ol' assembly, this lesson is a bit... stranger. Feel free to laugh at my attempt at expository narration:

You walk into a grassy field. Oddly enough, there appears to be a restaurant in the center of it all.
Even stranger, as you get closer, there seem to be two killer robots, who are wielding some
menacing guns. However, their faces quickly remove any possible intention of a swift death with you
at the wrong end of the gun. There is also a rabbit creature, the likes of which you have never seen before.
What an odd place.

Welcome to Cafe Assembly! Are you confused yet?

This is intended to teach you how to work with the logical instructions. Keep two things in mind here, as these are the basis of binary logic:

1 = true
0 = false

Let's say the waiter comes by and gives you a table to sit at. Now, you soon realize there are only two things on the menu: chinfish and yellow flowers.
You're no food connoisseur, but suppose you would like to try some of these dishes.

AND
You put down the menu, signaling to the waiter that you're done deciding what to order. He comes over, and you say, "I would like to have chinfish and yellow flowers."

The and statement is important. If the waiter gives you only chinfish, you will not be satisfied. If the waiter gives you only yellow flowers, you will not be satisfied. Likewise, if he gives you neither, you will certainly not be satisfied. You will only be satisfied if you get chinfish and yellow flowers together. Thus, both conditions must be true for an AND statement to be true.

The AND instruction in Assembly works the same way. An AND statement will be true only if both sides of the statement are true:

1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0

OR
If you say, "I want chinfish or yellow flowers," that means you'll be far more lenient about the possible outcomes. It's okay if the waiter gives you chinfish. It's also okay if the waiter gives you yellow flowers. Heck, if he gives you both, that's all right too. The only time when you'll be unsatisfied is if you do not get any dish.

An OR statement in assembly will be false only if both sides of the statement are false; the rest of the possibilities are true:

1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0

XOR
Now, XOR (the "exclusive or") is slightly harder to grasp. An XOR is essentially the same as an "Either (this) or (that), but not both" statement in English. You say to the waiter, "I want either chinfish or yellow flowers, but not both." You will be satisfied if he gives you a chinfish. You will be satisfied if he gives you yellow flowers. But you will not be satisfied if he gives you both, or if he gives you neither.

An XOR statement is true only if both sides are different. If both sides are the same, it is false:

1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0

It's too bad we don't use XOR in the English language. I totally want to say, "I'm going to the carnival xor the beach." If xor was a real word, this would mean "I'm going to the carnival, or I'm going to the beach, but I don't want to go to both."

NOT
Finally, we save the best for last. NOT is very simple: it just changes the binary digit to the other value.

NOT 1 = 0
NOT 0 = 1

Also notice that the NOT statement only takes 1 operand, unlike all the other logical statements, which need 2 operands.

Once again, Windows calculator comes to the rescue:
Windows XP Calc - Logical Instructions

Windows 7 Calc - Logical Instructions

Navigation
Previous Lesson: Binary
Next Lesson: Logic Instructions In Assembly
Table of Contents