/*
 * Indirect_Addr.asm
 *
 *  Modified: 29 Aug 2024
 *  Authors: Dr. Schwartz, Ivan Bukreyev
 *
 *	Indirect (indexed) addressing mode
 */ 

.include "ATxmega128A1Udef.inc"

.dseg
.org 0x2000
OutDat1:	.byte 2
OutDat2:	.byte 2

.CSEG 
.org 0x0000
	jmp Main

.org 0x100
DATA_I1:	.dw 0x3701
DATA_I2:	.dw 0x4744

.org 0x200
Main:
	ldi ZL, low(DATA_I1<<1)
	ldi ZH, high(DATA_I1<<1)
	lpm R16, Z+
	lpm R17, Z+
	lpm R18, Z+	
	lpm R19, Z

	ldi XL, low(OutDat1)	;Initialize X register
	ldi XH, high(OutDat1)
	st X+, R17				;Store R17 at 0x1000, increment X
	st X, R16				;Store R16 at address pointed by X
	
	ldi YL, low(OutDat1)	;Initialize Y register
	ldi YH, high(OutDat1)
	std Y+2, R19			;Store R19 at address pointed by Y+2 
	std Y+3, R18			;Store R18 at address 0x2000 + 3

	ld R21, Y+		;Load R21 from address pointed by Y, post increment Y
	ldd R20, Y+2	;Load R20 from address 0x2001 + 2 (R21:R20 = 3744)

HERE:
	rjmp HERE
