Section 03 Part 03 – The OR Instruction “Because an appeal makes logical sense is no guarantee that it will work.” ~William Bernbach

Introduction

OR – OR logical

This instruction will perform OR logical between the source operand and destination operand, the result is saved to the destination operand.

So what is OR logical?

Again, we need to look at this from a broad perspective.  Let us take two bits, one from the source operand and one from the destination operand, and perform OR logical:

 source operand destination operand Result 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1

The idea is that either one has to be 1 for the result to be 1.  To understand why it’s called OR, pretend that 0 is referred to as “false” and 1 is referred to as “true”.  So let’s look at the table again:

 source operand destination operand Result False OR False = False False OR True = True True OR False = True True OR True = True

The description of this logic is; “If the source or the destination, or both are true, then the result is true”, and that’s where the name originates.

Examples

So, here is an example (we’ll pretend that d0 contains 01234567, just like the AND example):

 ori.b     #\$EC,d0

This instruction will OR the byte EC with the byte 67 inside d0.  Since this is a binary instruction, EC and 67 in binary is 1110 1100 and 0110 0111.

 EC 1 1 1 0 1 1 0 0 OR OR OR OR OR OR OR OR OR 67 0 1 1 0 0 1 1 1 = = = = = = = = = EF 1 1 1 0 1 1 1 1

As you can see in the table, either the source or the destination (or even both of them), must be set to 1 for the result to be 1.

EC OR 67 = EF

And so, EF is saved into d0, d0 now contains 012345EF.

The OR instruction can do (and not do) pretty much the same as the AND instruction.  For example, you can OR one register to another:

 or.w      d0,d1

You can OR on memory in various ways too:

 ori.w     #\$07FF,\$00004000           or.w      d0,\$00004000           or.l      \$00004000,d7

And you can do it on memory using the address registers:

 ori.w     #\$07FF,(a1)           or.w      d0,(a3)           or.l      (a6),d7

Just like AND, you cannot do things such as OR-ing from one memory directly to another, or directly to an address register:

 or.w      \$00020000,\$0002004E           ori.w     #\$3F10,a0

OR Immediate

Again, just like “add”, “sub” and “AND”.  If the source operand is “immediate”, you must use the instruction “ori” instead of “or”:

 ori.w     #\$FC00,d0

Again, don’t worry if you use “or” instead, as the assembler will turn it into “ori” for you, when it assembles your code.