MBLogic for an open world in automation
A logic stack is one of the fundamental features of all conventional PLCs, although its presence is often not explicitly mentioned. The logic stack is the location where the results of logic operations are stored, and where many instructions implicitly draw one or more of their Boolean parameters.
The logic stack is implemented as a stack. This stack has an undefined maximum size, but the limit may be assumed to be very large, and for all practical purposes unlimited. The minimum size is zero.
Instructions which use the logic stack may push a value onto the stack, modify the top of the stack, read the top of the stack, or read any value below the top of the stack. In the instruction documentation, the top of the logic stack is refered to as "the top of the logic stack", "top of stack", or just "logic stack". Values in locations below the top of the stack are refered to as the logic stack value (top - 1) (the value just below the top of stack), or logic stack value (top - 2)(the value two positions below the top of stack). No instruction reads more than two positions below the top of stack.
Whenever a new network (rung) is started, the logic stack is cleared and the top of the stack is initialised to "false". If an instruction attempts to read a logic stack location which does not exist a value of "false" is returned to the instruction. This means that attempting to read an invalid logic stack location does not result in a run time error, but it does mean the instruction will never become true.
When a subroutine is called, the logic stack is re-initialised. When the subroutine returns, the state of the logic stack is undefined. This means that a subroutine must not rely on the logic stack being in a particular state when called, and the calling location must not rely on the logic stack being either set by the subroutine or being in the same state as before the subroutine call.
Example:
// Re-initialise the logic stack. // Push a value onto the stack. The top of stack is now true. NETWORK 1 STR SC1 // Re-initialise the logic stack again. // The previous value is now gone. NETWORK 2 // Re-initialise the logic stack again. // Push four values onto the stack. The top is true, // (top - 1) is false, (top - 2) and (top - 3) are true. NETWORK 3 STR SC1 STR SC1 STRN SC1 STR SC1 // Re-initialise the logic stack again. // The previous values are now gone. NETWORK 4