Programming Considerations
7-25
Interrupts
7.6
Programming Considerations
The interaction of the ’C62x/’C67x CPUs and sources of interrupts present
programming issues for you to consider when you are developing your code.
7.6.1
Single Assignment Programming
Example 7–10 shows code without single assignment and Example 7–11
shows code using the single assignment programming method.
To avoid unpredictable operation, you must employ the single assignment
method in code that can be interrupted. When an interrupt occurs, all instruc-
tions entering E1 prior to the beginning of interrupt processing are allowed to
complete execution (through E5). All other instructions are annulled and
refetched upon return from interrupt. The instructions encountered after the
return from the interrupt do not experience any delay slots from the instructions
prior to processing the interrupt. Thus, instructions with delay slots prior to the
interrupt can appear, to the instructions after the interrupt, to have fewer delay
slots than they actually have.
For example, suppose that register A1 contains 0 and register A0 points to a
memory location containing a value of 10 before reaching the code in
Example 7–10. The ADD instruction, which is in a delay slot of the LDW, sums
A2 with the value in A1 (0) and the result in A3 is just a copy of A2. If an interrupt
occurred between the LDW and ADD, the LDW would complete the update
of A1 (10), the interrupt would be processed, and the ADD would sum A1 (10)
with A2 and place the result in A3 (equal to A2 + 10). Obviously, this situation
produces incorrect results.
In Example 7–11, the single assignment method is used. The register A1 is
assigned only to the ADD input and not to the result of the LDW. Regardless
of the value of A6 with or without an interrupt, A1 does not change before it is
summed with A2. Result A3 is equal to A2.
Example 7–10. Code Without Single Assignment: Multiple Assignment of A1
LDW
.D1
*A0,A1
ADD
.L1
A1,A2,A3
NOP
3
MPY
.M1
A1,A4,A5
; uses new A1
Example 7–11. Code Using Single Assignment
LDW
.D1
*A0,A6
ADD
.L1
A1,A2,A3
NOP
3
MPY
.M1
A6,A4,A5 ; uses A6