; IPL-VI List Reversal Program
; Reverses a list structure

START:
    L0 = (A B C D E)    ; Create initial list
    L1 = NIL             ; Initialize empty result list

LOOP:
    J1 L0, DONE         ; Jump if L0 is empty
    L2 = H0 L0          ; Get head of L0
    L0 = T0 L0          ; Get tail of L0
    L1 = S2 L1, L2      ; Cons L2 onto L1
    J0 LOOP             ; Continue loop

DONE:
    OUT L1              ; Output reversed list
    HALT