This is the third and final part of a series on determining execution time of an assembly language program written for the MOS 6502. Part 1 can be found here and part 2 can be found here.
In this post I'll be trying to optimize the code from the previous posts to lower the execution time. Looking at the program without having tried to optimize an assembly program before, my gut tells me the 6 cycles dedicated to accessing the pointer to $0400
and iterating over it 1024 times could be a good place to start.
Removing the indirect address and restructuring the program to very explicitly fill each page individually should bring down the execution time by 1,081 microseconds. I'm sure there's further refinements you could make to improve execution time but given my very limited assembly knowledge that's all I've got for the moment. The code I used was as follows:
LDA #$07
LDY #$00
LOOP: STA $0200,Y
INY
BNE LOOP
LDA #$07
LOOP2: STA $0300,Y
INY
BNE LOOP2
LDA #$07
LOOP3: STA $0400,Y
INY
BNE LOOP3
LDA #$07
LOOP4: STA $0500,Y
INY
BNE LOOP4
Other experiments for this week's lab include filling the display with light blue:
This involved simply changing the colour code loaded into the accumulator to $e
from $07
.
Another experiment was to change the colour for each page to have 4 distinct sections:
Again, this just involved changing the colour code loaded into the accumulator for each loop - $e
, $a
, $f
, and $b
.
To wrap up, some thoughts and feelings about my first experience with assembly. It's definitely a disarming language, I'm in my last term now and feel like I know a decent amount about programming but assembly really strips that away and makes you look at the rote data being manipulated without all the assumptions and preconceived notions surrounding it. One of the hardest learning curves for me in completing this was going back to hexadecimal numbers, trying to remember details about overflows and binary number limits, although it is review for me I haven't touched those concepts in a meaningful way since first term which was almost 5 years ago now. Once I get a grip on those again it should help a lot in following the logic of how assembly programs work. Excited to get deeper into it!
Top comments (0)