Knowledge Base

Example (Intermediate): Combining semaphores (Boolean processing)

Semaphores can be combined using the Boolean (logical) instructions ANDORNOT and XOR. So long as you stick to those instructions, and not the “masked Boolean” AndM, OrM, NotM and XorM, you will get the expected results. If you are curious about why this is so, the answer is in the definition of the RecallS instruction.

For example, turn on output oValve only if (Vessel is full AND Cycle is complete) OR pressure is high (each of the conditions is represented by a semaphore that has been calculated somewhere else in the program):

        RecallS     sVesselFull     ;push sVesselFull onto stack
        RecallS     sCycleComplete  ;push sCycleComplete onto stack
        And                         ;AND the first two terms
        RecallS     sHighPressure   ;push sHighPressure onto stack
        OR                          ;OR in the third term
        Output      oValve          ;Send the outcome to the valve

To understand this code fragment you need to understand how the register stack works. That is covered in the SPLat/PC helpfile.