View Single Post
Old 21 February 2020, 14:03   #171
Antiriad_UK
OCS forever!

Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 190
This is one I saw in another thread that made me scratch my head for a while is using add dx,dx to simultaneously test and clear a "flag". For example you have a loop where you are setting a flag from 0 to 1 if something occurred. Then at the end of the loop you check the flag to see if you need to loop again and reset the flag (sorting routine I did this in).

Instead of:
Code:
.loop:
	moveq	#0,d0			;reset flag
	...
	;If something occured, flag it
	moveq	#1,d0
	...
	;Do we need to loop again?
	tst.w	d0
	bne.s	.loop
Do this:
Code:
	moveq	#0,d0			;reset flag once
.loop:
	...
	;If something occured, flag it
	moveq	#-128,d0		;set flag = $80 ($fffffff80)
	...
	;Do we need to loop again? Also reset flag
	add.b	d0,d0
	bcs.s	.loop
Can do the same thing with subq and bmi, but I liked the use of carry
Antiriad_UK is offline  
 
Page generated in 0.04217 seconds with 11 queries