SAVING CPU STATUS DURING INTERRUPTS
When the 8051 hardware recognizes an interrupt request, program control branches automatically to the corresponding service routine, by forcing the CPU to process a long CALL (L CALL) instruction to the appropriate address. The return address is stored on the top of the stack. After completing the service routine, an RETI instruction returns the processor to the background program at the point from which it was interrupted.
If the SP register held IF H when the interrupt was detected, then while the service routine was in progress the stack would hold the registers SP would contain 26H. This is the most general case; if the service routine doesn't alter the B-register and data pointer, for example, the instructions saving and restoring those registers could be omitted.
PASSING PARAMETERS ON THE STACK
The stack area of the internal RAM is used to automatically store the address, called the return address, of the instruction found immediately after the call. The Stack Pointer register holds the address of the last space used on the stack. It stores the return address above this space, adjusting itself upward the return address is stored.
The stack may also pass parameters to and from subroutines. The stack parameter passing can be easily understood with the help of the depicts the following sequence of events.
-
A call opcode occurs in the program software, or an interrupt is generated in hardware in hardware circuitry.
-
The return address of the next instruction after the call instruction or interrupt is found in the program counter.
-
The return address bytes are pushed on the stack, low byte first.
-
The stack pointer is incremented for each push on the stack.
-
The subroutine address is placed in the program counter.
The subroutine is executed.
-
A RET (return) opcode is encountered at the end of the subroutine.
-
Two pop operations restore the return address to the PC from the stack area in internal RAM
-
The stack pointer is decremented for each address byte pop.
BACK |