AVR汇编语言如何实现如 LJMP @A+DPTR这样的散转结构
.include "8515def.inc"
.dseg
keyone: .byte 1
.cseg
rjmp reset
.org 0x10
RESET:
ldi r16,low(RAMEND) ; ram 的顶端
ldi r17,high(RAMEND)
out spl,r16 ; 设置堆栈指针指向ram顶部
out sph,r17
ldi r16,1
sts keyone,r16 ;变量初始化
L2:
lds R20,keyone
ldi R24,low(L8) ;取散转表首地址
ldi R25,high(L8)
clr r21
subi r20,1 ;计算表内偏移量
sbci r21,0
lsl r20 ;注意对FLASH的地址是字寻址
rol r21
add r24,r20 ;相当于 @a+dptr
adc r25,r21
mov R30,R24
mov R31,R25
ijmp ;间接跳转指令,指向 z=r30,31
L8:
rcall prog1
rjmp L6
rcall prog2
rjmp L6
rcall prog3
rjmp L6
rcall prog4
rjmp L6
rcall prog5
L6:
NOP
rjmp L2
ret
prog1:
ldi R24,2
sts keyone,R24
ret
prog2:
ldi R24,3
sts keyone,R24
ret
prog3:
ldi R24,4
sts keyone,R24
ret
prog4:
ldi R24,5
sts keyone,R24
ret
prog5:
ldi R24,1
sts keyone,R24
ret