OR - The Bitwise OR Command
The OR command is a bitwise operation that OR’s the value held in the accumulator with the specified value (argument) and resaves the new value into the accumulator.
"OR"ing a bit turns it on. The value you specify in the command is known as a mask. Bits in the argument that are on will become on in the result. Bits that are off in the argument will maintain state in the result.
Sometimes it is useful to store binary states in a single byte and use bitwise operations like this to do targeted edits. One example would be tracking partition states in a ballroom.
You can preform an advanced version of this command using the X register to load from an array.
This command is the opposite of the AND command.
ACC |
1 |
1 |
1 |
0 |
0 |
0 |
0 |
1 |
MASK |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
0 |
RESULT |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
Examples
Example 1
{
LDA #0xA0 //Load the value in 0xA0 to the accumulator
OR #0x01 //Use OR to turn on bit 1 regardless of the previous state
STA ~1 //Store the new result of #0xA1 into ~1
}
Example 2
{
LDA ~2 //Copy the value in ~2 to the Accumulator
OR ~10 //OR with the value in ~10 (the Mask)
STA ~2 //Copy the result from the Accumulator to ~2
}
Example 3
This excerpt stores the state of a partition into a single byte tracking all of them.
{
...
Partition1:
LDA PresetByte //get preset byte
CMP #0 //preset 1
BRZ Part1P1
CMP #3 //preset 4
BRZ Part1P4
Null
Part1P1: //Partition open
LDA RoomState
OR #0x01 //Set the bit to on
STA RoomState
BRA SendMessage
Part1P4: //Partition closed
LDA RoomState
AND #0xFE //Set the bit to off
STA RoomState
BRA SendMessage
...
}
Example 4
ORing with a value in an array using the X register.
This task snippet would be used to turn a single bit off or on using an array.
OR_Array: Send2(0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80)
AND_Array: Send2(0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F)
{
Start(0x1c,PartitionArea,x,0x6b,x,x,x) //Start on incoming messages from partitions
copy @0,~0,7 //Copy to bytes
LDA ChannelByte //Load the channel number
ADD #5 //Add 5 to offset for the array
SWAP //Swap to X reg
LDA PresetByte //Load the preset number
BNE PartitionClose //Is it P1(Open)? If not assume closed
LDA RoomState //Load the previous partition states
OR OR_Array,x //Or the value in the array offset by the partition number(ch)
STA RoomState //Restore the new state
BRA SendMessage //Go send the new join messages
PartitionClose:
LDA RoomState //Load the previous partition states
AND AND_Array,x //AND the value in the array offset by the partition number(ch)
STA RoomState //Restore the new state
SendMessage: //Go send the new join messages
...
}