The particular code that is executed whenever an interrupt occurs is determined by a set of addresses called interrupt vectors that are stored in low memory.
The system state is saved before the interrupt service routine is executed and is restored afterward.