I'm having some trouble handling interrupts in the middle of hardware loops. Depending on where the interrupt occurs, its "rti" instruction doesn't return the execution where it would have gone without the interrupt. I'll illustrate it with an example:
I have the following C code:
int i, j, sum = 0;
for (i = 1; i < 10; i++)
for(j = 1; j < i; j++)
sum += j;
I compile it with optimization  so the compiler creates hardware loops. This is the assembler output:
lcntr=0x9, do (pc,0x7) until lce;
if ge jump (pc, 0x5);
lcntr=r8, do (pc,0x2) until lce; <--------------
(... printf ...)
If the code is executed without interrupts, the correct result of the sum, which is stored in R2, is 120. However, with interrupts this result is not always obtained:
I put a breakpoint in the marked instruction, the second "do until". When execution stops on the breakpoint I create by hand an IRQ0 interruption, whose handler has a single plain "rti" instruction. Execution then continues without any other interruption until the loop ends.
While in the VisualDSP++ simulator, this scenario gives an incorrect sum of 165. Working with the HPUSB-ICE emulator with the EZ-Board gives 84.
Am I missing something, or is this a hardware/simulator anomaly?