OR
When we use logical bitwise OR we are making a bit-to-bit comparison of two 8-bit values. Each bit is compared within the same position and if either match 1 then 1 is the result. See logic table below for further illustration.
This operation is particularly useful for masking bits. Certain bits are preserved based on the mask used.
Note, it is possible to include A as the first parameter but this can be ommitted due to it only ever supporting A. i.e. OR B and OR A, B are the same.
Note, OR A is a great way to clear Carry flag
| A | ? | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
| Example | ||
| A | B | Result |
| 10010011 | 10101110 | 10101111 |
We can think of the logic of OR quite easily in the perspectives of other programming languages. Take the following psuode code for example:
- if( false OR false ) this will never fire
- if( false OR true ) then do this
- if( true OR false ) then do this
- if( true OR true ) then do this
| Instruction | Description | Opcode |
|---|---|---|
| OR A | Compare A with itself | B7 |
| OR B | Compare the 8-bit number in B register with value in A register | B0 |
| OR C | Compare the 8-bit number in C register with value in A register | B1 |
| OR D | Compare the 8-bit number in D register with value in A register | B2 |
| OR E | Compare the 8-bit number in E register with value in A register | B3 |
| OR H | Compare the 8-bit number in H register with value in A register | B4 |
| OR L | Compare the 8-bit number in L register with value in A register | B5 |
| OR {??} | Compare the 8-bit immediate number with value in A register | F6 {??} |
| OR (HL) | Compare the 8-bit number at memory address HL with value in A register | B6 |
| OR (IX+displacement) | Compare the 8-bit value in IX with value in A register | DD B6 {??} |
| OR (IY+displacement) | Compare the 8-bit value in IY with value in A register | FD B6 {??} |