--- In AVR-Chat@yahoogroups.com, "leon_heller" <leon.heller@d...>
wrote:
> I've just written a simple jump table program using ICALL:
Your jump table would be better if it consisted only of addresses as
opposed to the call/return. That saves both time and space. I use
the GNU assembler (comes with gcc) but the idea is the same. You'll
just have to convert to the Atmel way of doing things.
Also, unless you can guarantee that the table doesn't cross a 256-byte
boundary you need to propagate the carry to the high byte.
Depending on what registers you have available, this code can be made
shorter and more efficient. This is written using gcc register
conventions. In particular, r0 is a temporary register and r1 is
always zero. This code also assumes that the index value (in r24) is
never more than 127.
ldi r30, lo8(jmpTable)
ldi r31, hi8(jmpTable)
add r24, r24
add r30, r24
adc r31, r1
ld r0, Z+
ld r31, Z
mov r30, r0
icall
; this table contains the program memory addresses of the specified
labels
jmpTable:
.word pm(one)
.word pm(two)
.word pm(three)
...
.word pm(eight)