Skip to content

LFL — LIFO Load

Category
Shift / Sequencer
Type
Output
Availability
All platforms

LFL instruction block: Source Push_Val, File Stack, Length 4, Position, with DN and EM indicators


LFL (LIFO Load) pushes a value onto a last-in, first-out stack each time its rung goes from false to true. The stack is an array tag; the control tag’s position is the number of entries and the index the next push lands in. LFL pairs with an LFU (LIFO Unload) on the same control tag and array, which pops the newest entry. Use a stack to retrace steps: the last position visited, the last recipe change, the last fault. Do not use it where order of arrival matters; that is a FIFO.


Operand Type Format Valid Range Required Description
Control CONTROL tag Tag or Tag[n] Shared with exactly one LFU Yes Holds LEN, POS and the status bits.
Source INT or DINT tag, member, element or literal Tag, 9 Any Yes The value pushed.
File INT or DINT array tag Tag At least Length + 1 elements Yes The stack. Entries occupy elements 0 to POS − 1; the newest is at POS − 1.
Length Whole number 4 1 to array size − 1 Yes Stack capacity.
Position Whole number 0 0 to Length No Entries at power-up; normally 0.

LEN is loaded from Length and POS from Position.

EN is cleared. Nothing is pushed.

On the scan the rung turns true, if POS is below LEN the Source is written to File[POS] and POS increments. DN is set while POS equals LEN, so a push against a full stack is ignored. EM is set while POS is 0.

Nothing.

Condition EN DN EM POS File
Power-up 0 0 1 0 holds
Rung false 0 holds holds holds holds
False → true, POS < LEN 1 POS = LEN after 0 +1 File[POS] = Source
False → true, POS = LEN 1 1 0 holds holds
RES on the control 0 0 0 0 holds

Bit Mnemonic Data type Set by Cleared by Operation description
Enable .EN BOOL The LFL rung being true The LFL rung being false, or RES Mirrors the load rung, and is the load half’s edge memory.
Enable unload .EU BOOL The LFU rung being true The LFU rung being false, or RES Mirrors the unload rung, and is the unload half’s edge memory. Two bits, so the two rungs never disturb each other’s edge.
Done .DN BOOL POS reaching LEN An unload, or RES The stack is full; further loads are ignored.
Empty .EM BOOL POS at 0 after a load or unload The first load, or RES The stack is empty; an unload does nothing.
Error .ER BOOL Never RES Reserved. Bad operands are refused at validation.
Unload .UL BOOL Never RES Not used by LIFO.
Inhibit .IN BOOL Never RES Reserved.
Found .FD BOOL Never RES Not used by LIFO.
Length .LEN INT Length at power-up Never (RES preserves it) Stack capacity.
Position .POS INT Each load (+1) and unload (−1) RES (to 0) Number of entries; also the index of the next push.

Scenario: A pick-and-place records each position it visits so an operator can step it back through them in reverse order after a jam.

Tags:

  • Push — Position reached, BOOL
  • Push_Val — Position number, INT
  • Stack — The stack, INT[8]
  • Stack_Ctl — Control, CONTROL, Length 4
  • Pop — Step back, BOOL
  • Pop_Val — Position to return to, INT

Rungs 1 and 2:

—] [Push———[LFL Stack_Ctl Push_Val Stack 4]———
—] [Pop———[LFU Stack_Ctl Stack Pop_Val 4]———

Scan 1 — both rungs false. Push_Val reads 9. Position 0 and EM lit say the stack is empty. The stack has already been through one push and pop here, which is why Stack still lists a 9 in element 0 and Pop_Val still reads 9: a pop moves Position, it does not erase anything, and Dest keeps its last value.

Figure 1 — LFL and LFU rungs false: Push_Val 9, Stack listing a stale 9, Position 0, EM lit on both, Pop_Val 9 from the previous cycle

Scan 2 — Push = 1. 9 is pushed: Stack[0] becomes 9, Position 1, EM dark.

Figure 2 — LFL rung true after one edge: Position 1, EM dark, LFL rung lit

Scan 3 — Pop = 1. The LFU pops the newest entry: Pop_Val reads 9, Position 0, EM lit.

Figure 3 — LFU rung true after one edge: Pop_Val 9, Position 0, EM lit, LFU rung lit

Push 9, 12 and 15 in turn and three pops return 15, 12, 9: the reverse of the order they went in, which is what “step back” needs.


Error definitions

.ER cause Condition that sets it .POS / status value Meaning
None .ER is never set by LadderIDE — A File that is not an INT/DINT array, a Length of array size or more, or a third instruction on the control tag is refused at validation.

Troubleshooting hints

Symptom: Pushes are lost. Likely cause: The stack is full; .DN is set. Fix: Increase Length and the array, or block the push with XIO Stack_Ctl.DN.

Symptom: Pops come out in arrival order. Likely cause: An FFU was placed instead of an LFU. Fix: Read the block title; LFU pops from File[POS − 1], FFU from File[0].



No shifting. Unlike a FIFO, a pop does not move the other entries; POS simply steps back, so a LIFO costs nothing per entry.

The block colours neutral. Watch the rung wire, the Position row and the DN/EM indicators.

Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11