When using index registers in a block it is good practice to save/restore the value to a local variable or use push/pop, and if the index value should be retained restore and save it to a global variable. You may also check the U/G addressing mode for module reference in a block.