it turns out that this should be a bug in the compiler as well as in
the gdb sim target.
Since CALL decrements the stack pointer to save the return address, a
register indexed call using the stack pointer must account for this.
The SP is decremented before the address of the target operand is
calculated; thus, for a SP indexed call, the index must be incremented
by 2.
According slau049d not. (page 3-29)
"
Syntax CALL dst
Operation dst -> tmp dst is evaluated
and stored // BEFORE SP modify !
SP-2 -> SP
"
Well... you are right, that's what on top of the page. At the bottom, it says:
SP-2 -> SP, PC+2 -> @SP, X(R5) -> PC
which is at least confusing, and at worst contradictory.
Try it on hardware though, and you'll find the device behaves like described on
the bottom.
Heiko