Memory Copy Code optimization. Help needed!

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Memory Copy Code optimization. Help needed!

Post 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
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Memory Copy Code optimization. Help needed!

Post 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.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: Memory Copy Code optimization. Help needed!

Post by MrSterlingBS »

:idea: THX
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: Memory Copy Code optimization. Help needed!

Post by MrSterlingBS »

The save of CYCLES is about 550. 892 cycles instead of 1444.
Not huge but a little bit faster.
Post Reply