The compiler’s job is to ensure that index registers that are used in interrupt programs or in functions or function blocks called from interrupt programs are not overwritten.
The example below shows the concept of the code generation for PLCs (index register in interrupt: program code, programmer’s comments on the right) to ensure this behavior:
INT0
ST R9010
F411_CHGB K1 Index register bank set to 1
ST R9010
F0_MV DT458, I5 Actual program code
F0_MV K5, I5DT455
ST R9010
F412_POPB Index register bank resetINT0
ST R9010
F0_MV I5, DT461 Protecting the current content
ST R9010
F0_MV DT458, I5 Actual program code
F0_MV K5, I5DT455
ST R9010F0_MV DT461, I5 Rewriting the current content
IRET