DATA_BLOCK DB 1
STRUCT 	
	DT1	: DATE_AND_TIME := DT#1990-1-1-0:0:0.000;
	DT2	: DATE_AND_TIME := DT#1990-1-1-0:0:0.000;
	DT3	: DATE_AND_TIME := DT#1990-1-1-0:0:0.000;
END_STRUCT;
BEGIN
	DT1 := DT#1990-1-1-0:0:0.000; 
	DT2 := DT#1990-1-1-0:0:0.000; 
	DT3 := DT#1990-1-1-0:0:0.000; 
END_DATA_BLOCK


FUNCTION FC 1 : VOID
VAR_TEMP
	DBNR	: INT;
END_VAR
BEGIN
	AUF		DB 1
	LAR1		P#DBX 0.0

	// Rotate DB1.DT1 one bit to the left
	L		D [AR1,P#4.0]
	UD		DW#16#80000000
	L		D [AR1,P#0.0]
	RLDA
	T		D [AR1,P#0.0]
	L		D [AR1,P#4.0]
	RLDA
	T		D [AR1,P#4.0]

	// Rotate DB1.DT2 one bit to the left
	L		D [AR1,P#12.0]
	UD		DW#16#80000000
	L		D [AR1,P#8.0]
	RLDA
	T		D [AR1,P#8.0]
	L		D [AR1,P#12.0]
	RLDA
	T		D [AR1,P#12.0]

	// Clobber DB and DI registers
	L		0
	T		#DBNR
	AUF		DB [#DBNR]
	AUF		DI [#DBNR]

	// Compare DB1.DT1 to DB1.DT2
	// Should be equal
	CALL "EQ_DT" (
		DT1	:= DB1.DT1,
		DT2	:= DB1.DT2,
		RET_VAL	:= M 0.0,
	)
	U		M 0.0
	__ASSERT==	__STW VKE,	1

	// Clobber DB and DI registers
	L		0
	T		#DBNR
	AUF		DB [#DBNR]
	AUF		DI [#DBNR]

	// Compare DB1.DT1 to DB1.DT3
	// Should be not equal
	CALL "EQ_DT" (
		DT1	:= DB1.DT1,
		DT2	:= DB1.DT3,
		RET_VAL	:= M 0.1,
	)
	U		M 0.1
	__ASSERT==	__STW VKE,	0

	// Decrement the test counter.
	// Stop test, if it reaches zero.
	AUF		DB 1
	U		DBX 0.0
	ZR		Z 0
	U		Z 0
	SPB		m003
	CALL		SFC 46 // Stop CPU
m003:	NOP		0
END_FUNCTION


ORGANIZATION_BLOCK OB 1
BEGIN
	CALL		FC 1
END_ORGANIZATION_BLOCK


ORGANIZATION_BLOCK OB 100
BEGIN
	AUF		DB 1
	LAR1		P#DBX 0.0

	// Initialize DB1.DT1 (one bit set)
	L		1
	T		D [AR1,P#0.0]
	L		0
	T		D [AR1,P#4.0]

	// Initialize DB1.DT2 (one bit set)
	L		1
	T		D [AR1,P#8.0]
	L		0
	T		D [AR1,P#12.0]

	// Initialize DB1.DT3 (all bits clear)
	L		0
	T		D [AR1,P#16.0]
	L		0
	T		D [AR1,P#20.0]

	// Initialize the test counter.
	// Run 10 test loops.
	L		C#10
	CLR
	S		Z 0
	SET
	S		Z 0
END_ORGANIZATION_BLOCK
