Chapter 4. Ladder Diagram (LD) ProgrammingGFK-2950C February 2018 1834.9.6 LIFO WriteThe Last-In-First-Out (LIFO) Write (LIFO_WRT) function incrementsthe table pointer by one and then adds an entry at the new pointerlocation in a table. Values are always moved in at the top of thetable. If the pointer reaches the last location and the table becomesfull, LIFO_WRT cannot add further values. LIFO_RD must then beused to remove the entry at the pointer location and decrement thepointer by one.Mnemonics:LIFO_WRT_DINTLIFO_WRT_DWORDLIFO_WRT_INTLIFO_WRT_UINTLIFO_WRT_WORD1. LIFO_WRT increments the table pointer by one.2. LIFO_WRT copies data from input parameter IN to the position in the table indicated by thepointer. (It writes over any value currently at that location.) Additional program logic must thenbe used to place the data in the input reference.3. Steps 1 and 2 are repeated each time LIFO_WRT is executed, until the table is full (PTR=LEN).The pointer does not wrap around when the table is full.When LIFO_WRT receives power flow, the pointer increments by 1; then the new data is written atthe pointer location. If the pointer was already at the last location in the table, no data is written andLIFO_WRT does not pass power to the right. The pointer always indicates the last item entered intothe table. If the table is full, it is not possible to add more entries to it.LIFO_WRT passes power to the right after a successful execution (PTR < LEN).Note: A LIFO table is a stack. A FIFO table is a queue.Operands for LIFO WriteNote: For each mnemonic, use the corresponding data type for the TB and IN operands. Forexample, LIFO_WRT_DINT requires TB and Q to be DINT variables.Parameter Description Allowed Operands OptionalLength (??) 1 Length 32,767. Constants NoTB (must be thesame type as IN)The elements in the table All except constants, S, data flow. SA -SC allowed only for WORD, DWORD.NoPTR Pointer. Index of the next element towrite.All except constants, S - SC, and dataflowNoIN (must be thesame type as TB)The element to write to the table All. S – SC allowed only for WORD,DWORDNoFL Energized when IN is written to thelast element of the tableAll NoExample for LIFO WritePRODUCT is a LIFO table with 100 word-sized elements. When theenabling input STORE is ON, a data item from NEW_ITEM is copiedto the table location pointed to by the value in STK_PTR. Output FLpasses power when PTR = LEN, firing the FULL coil. No further datafrom NEW_ITEM can be added to the table without first copyingdata out, using the LIFO_RD function.