Chapter 6
Chapter 6
The arithmetic status bits are found in Word 0, bits 0 to 3 in the controller status file. After an instruction is
executed, the arithmetic status bits in the status file are updated:
When using either an SLC 5/03 (OS301 and higher), SLC 5/04, or SLC 5/05 processor; floating point and string
values (specified at the word level) are supported.
+, -, *, | (DIV), SQR, - (NEG), NOT, XOR, OR, AND, TOD, FRD, LN, TAN, ABS, DEG, RAD, SIN, COS, ATN, ASN,
ACS, LOG, and ** (XPY).
The execution time of a CPT instruction is longer than a single arithmetic operation and uses more instruction words
The last bit is shifted out of the array and stored in the unload bit (UL
bit 10).
The shift is completed immediately.
For wraparound operation, set the position of the bit address to the last
bit of the array or to the UL bit, whichever applies.
If you wish to shift more than one bit per scan, you must create a loop
in your application using the JMP, LBL, and CTU instructions.
The instruction invalidates all bits beyond the last bit in the array (as
defined by the length) up to the next word boundary
Jumping forward to a label saves program scan time by omitting a program segment until needed.
Use a counter, timer, or the program scan register (system status register, word S:3, bits 0 to 7) to
limit the amount of time you spend looping inside of JMP/LBL instructions.
Enter a decimal label number from 0 to 255 in each subroutine file.
The JMP instruction causes the controller to skip rungs. You can jump to the same label from one or
more JMP instructions
This input instruction is the target of JMP instructions having the same label number.
You must program this instruction as the first instruction of a rung. This instruction has no control
bits.
You can program multiple jumps to the same label by assigning the same label number to multiple
JMP instructions. However, label numbers must be unique.
if (X>5)
Y= 4X+1;
else
Y= X3-2X+1
Implement the following C++ code using Ladder Logic assume A is stored in N7:1 and
i in N7:2:
The controller does not update I/O until it reaches the end of the main program (after executing all subroutines).
Outputs controlled within a subroutine remain in their last state until the subroutine is executed again.
Nesting subroutines allows you to direct program flow from the main program to a subroutine and then on to another
subroutine. The following rules apply when nesting subroutines.
With Fixed and SLC 5/01 processors, you can nest subroutines up to four levels
With SLC 5/02 and higher processors, you can nest subroutines up to eight levels.
An error occurs if more than the allowable levels of subroutines are called (subroutine stack overflow) or if more returns are
executed than there are call levels (subroutine stack underflow).
When the JSR instruction is executed, the controller jumps to the subroutine instruction (SBR) at the beginning of the target subroutine file and
resumes execution at that point.
You cannot jump into any part of a subroutine except the first instruction in that file.
You must program each subroutine in its own program file by assigning a unique file number (3 to 255)
Using SBR
The target subroutine is identified by the file number that you entered in the JSR instruction. This instruction serves as a label or identifier for a
program file as a regular subroutine file.
This instruction has no control bits. It is always evaluated as true. The instruction must be programmed as the first instruction of the first rung of a
subroutine. Use of this instruction is optional; however, we recommend using it for clarity.
Using RET
This output instruction marks the end of subroutine execution or the end of the subroutine file.
It causes the controller to resume execution at the instruction following the JSR instruction.
If a sequence of nested subroutines is involved, the instruction causes the processor to return program execution to the previous subroutine.
Without an RET instruction, the END instruction (always present in the subroutine) automatically returns program execution to the instruction following
the JSR instruction in your calling ladder file.