Have you tried changing IF debug_out = 1 then DEBUG "Sw1 On_status= ", dec on_status, " Mode = ", DEC mode, 13, 10

to
Code:
IF debug_out = 1 then 
  DEBUG "Sw1 On_status= ", dec on_status, " Mode = ", DEC mode, 13, 10
ENDIF
It may be interpreting the DEBUG command as a label to jump to?