Page 1 of 1

Memory Copy Code optimization. Help needed!

Posted: Fri Dec 29, 2023 8:59 am
by MrSterlingBS
Hello,

for a sub routine i have this code snippet.

Code: Select all

	LDY #$1F
	LDA #$00
Loop:
	STA $1A00,Y					
	STA $1A20,Y
	STA $1A40,Y
	DEY
	BPL Loop
And for some other reasons i have this one:

Code: Select all

	LDY #$5F
	;LDY #$1F
Loop:
	LDA $1A00,Y
	STA (VarP),Y
	;LDA $1A20,Y
	;STA (VarP+$20),Y
	;LDA $1A40,Y
	;STA (VarP+$40),Y
	DEY
	BPL Loop
The VarP contains the Low and Highbyte of a Memory location.
But how can i optimazed it to the first routine?
Is this possible?

Best regards
Sven

Re: Memory Copy Code optimization. Help needed!

Posted: Fri Dec 29, 2023 9:50 am
by chysn
It would be kind of the same, but you'd use three pairs of zero page pointers, like this (assuming the pairs are consecutive):

Code: Select all

sta (zp),y
sta (zp+2),y
sta (zp+4),y
It it worth it? Not for me to say, but I can't imagine ever doing it.

Also, don't overlook self-modifying code.

Re: Memory Copy Code optimization. Help needed!

Posted: Fri Dec 29, 2023 12:06 pm
by MrSterlingBS
:idea: THX

Re: Memory Copy Code optimization. Help needed!

Posted: Fri Dec 29, 2023 1:03 pm
by MrSterlingBS
The save of CYCLES is about 550. 892 cycles instead of 1444.
Not huge but a little bit faster.