SHR - The Shift Right Command
The SHR command is a bitwise operation that takes the value in the accumulator and moves all of the bits to towards the LSB (to the right). The bit in the LSB is placed into the Carry Flag and a zero value is placed in the MSB.
After 8 SHR commands the value will be 0.
You can use this in conjunction with the BCC and BRC commands to interrogate individual bits without destroying their contents.
This command is the opposite of the SHL command.
Syntax
SHR
Notice that there are no values attached to the command. It simply moves everything one spot right putting the LSB in the Carry Flag and clearing the MSB.
The SHR command has the byproduct of dividing the value by 2. |
Examples
Example 1
Task1()
{
Name="Dipswitch checker" //Branches on the lowest dipswitch set
LDA ^59,0 //Get the dipswitch port
SHR //Move Dipswitch 1 into the carry flag
BRC DipSwitch1Set //If carry flag is set branch.
SHR //Move next Dipswitch into the carry flag
BRC DipSwitch2Set //If carry flag is set branch.
...
}
Example 2
Task1()
{
Name="Occupancy Trigger" //Checks the state of dry contact 3.
LDA ^17,0 //Get the dry contact port
SHR //Move dry contact 1 into the carry flag
SHR //Move dry contact 2 into the carry flag
SHR //Move dry contact 3 into the carry flag
BRC Occupancy //If carry flag is set sensor saw motion
...
}