beautypg.com

Texas Instruments MSC1210 User Manual

Page 123

background image

Register Protection

10-17

Interrupts

The guts of the interrupt are the MOV instruction and the ADD instruction.
However, these two instructions modify the accumulator (the MOV instruction)
and also modify the value of the carry bit (the ADD instruction will cause the
carry bit to be set). The routine pushes the original values onto the stack using
the PUSH instruction because an interrupt routine must ensure that the regis-
ters remain unchanged by the routine. It is then free to use the registers it pro-
tected as needed. Once the interrupt has finished its task, it POPs the original
values back into the registers. When the interrupt exits, the main program will
never know the difference because the registers are exactly the same as they
were before the interrupt executed.

In general, the ISR must protect the following registers:

1) Program Status Word SFR (PSW)

2) Data Pointer SFRs (DPH/DPL)

3) Accumulator (ACC)

4) B Register (B)

5) R Registers (R0−R7)

Remember that the PSW consists of many individual bits that are set by vari-
ous instructions. Unless you are absolutely sure and have a complete under-
standing of what instructions set what bits, it is generally a good idea to always
protect the PSW by PUSHing and POPing it off the stack at the beginning and
end of the interrupts.

Also note that most assemblers will not allow the execution of the instruction:

PUSH R0

;Error − Invalid instruction!

This is due to the fact that, depending on which register bank is selected, R0
may refer to either internal RAM address 00

H

, 08

H

, 10

H

, or 18

H

. R0, in and of

itself, is not a valid memory address that the PUSH and POP instructions can
use.

Thus, if using any R register in the interrupt routine, push the absolute address
of that register onto the stack instead of just saying PUSH R0. For example,
instead of PUSH R0, execute:

PUSH Reg0

;Requires use of definition file MSC1210.INC

If the MSC1210.INC definition file has not been included in the project, the reg-
ister must be protected with:

PUSH 00h

;Pushes R0 onto stack, if using register bank 0

Of course, this only works if the default register bank (bank 0) has been se-
lected. If using an alternate register set, PUSH the address that corresponds
to the register in the bank being used.