Hi, i am running this code in order to add the data from the sram addreses 0x060 to 0x063 by using two subroutines (the first one adds the data of sram addresses into R1,R0 and the second performs the sign extension in the register R3). Although, in the second return(RET) from the ADDEXT subroutine the program counter returns to the first line of code instead in the point of where the first subroutine is rcalled.Can anyone help with debugging i think there is a mistake in the return address of the first RET in the subroutine ADDEXT, Thank you in Advance.
.include"m32def.inc"
.equ ram=0x060
.equ datalen=4
.def metritis=r16
ldi r19,low(RAMEND)
OUT SPL,R19
ldi r19,high(RAMEND)
OUT SPH,R19
ldi r18,0x0A
ldi metritis,datalen
ldi XL,low(ram)
ldi XH,high(ram)
loop:
st X+,r18
INC R18
dec metritis
brne loop
ldi XL,low(ram)
ldi XH,high(ram)
LD R22,-X
RCALL ADDEXT
ADDEXT:
ADIW XH:XL,1
RCALL SignExt
ADD R0,R2
ADC R1,R3
RET
SignExt://Sign Extension
ld R2,X
CLR R3
TST R2
BRPL synex
DEC R3
synex:
ret
telos:
rjmp telos