Wait loop

Z MAM wiki

(Rozdíly mezi verzemi)
Přejít na: navigace, hledání
(wait loop tricks explained)
m (typo)
 
Řádka 16: Řádka 16:
*We use INC until we reach zero thanks to overflow (253 -> 254 -> 255 -> 0)
*We use INC until we reach zero thanks to overflow (253 -> 254 -> 255 -> 0)
-
*R1, R2 are never initialized, we hope they still do zontain 0 we left there last time around
+
*R1, R2 are never initialized, we hope they still do contain 0 we left there last time around
We cannot use R3 instead if R16, instruction LDI only works for R16..32. Instruction BRNE (Branch If Not Equal) jumps if the last INC did not reach zero (flag Z stores this information).
We cannot use R3 instead if R16, instruction LDI only works for R16..32. Instruction BRNE (Branch If Not Equal) jumps if the last INC did not reach zero (flag Z stores this information).

Aktuální verze z 24. 2. 2012, 13:29

This piece of code is a simple wait loop (rather too simple):

WAIT:
	LDI	R16, 4			; LDI - Load Immediate
WAIT1:	INC	R1
	BRNE	WAIT1
	INC	R2
	BRNE	WAIT1
	DEC	R16
	BRNE	WAIT1
	RET

Few dirty tricks should be explained:

  • We use INC until we reach zero thanks to overflow (253 -> 254 -> 255 -> 0)
  • R1, R2 are never initialized, we hope they still do contain 0 we left there last time around

We cannot use R3 instead if R16, instruction LDI only works for R16..32. Instruction BRNE (Branch If Not Equal) jumps if the last INC did not reach zero (flag Z stores this information).

Osobní nástroje