ARM Technical Support Knowledge Articles

SAVING REGISTERS IN INTERRUPTS

Applies to: C51 C Compiler

Answer

QUESTION

I use the C51 compiler and when I look at the assembler listing for interrupt service routines (written in C), I notice that the current register bank did not get saved on stack.

If I specify the interrupt service routine to use the same register bank as the code, does that mean these registers get overwritten by the ISR?

ANSWER

Yes, it does. The following explanation will help to clear this.

When you declare your interrupt routine as follows...

void ISR (void) interrupt x
{
}

C51 saves registers used in the ISR on the stack using PUSH/POP.

When you declare your interrupt routine as follows...

void ISR (void) interrupt x using 1 (or 2 or 3)
{
}

C51 switches to a new register bank (by changing the RB bits in the PSW). It only needs to save the original PSW on the stack.

When you declare your interrupt routine as follows...

void ISR (void) interrupt x using 0
{
}

the interrupt code WILL overwrite the registers used by your program. So, don't use USING 0. EVER!!!

Article last edited on: 2004-06-07 10:13:28

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential