DEV Community

gus
gus

Posted on

3 1

Calculating 6502 Execution Time - Part 3

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.

Image description

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
Enter fullscreen mode Exit fullscreen mode

Other experiments for this week's lab include filling the display with light blue:

Image description

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:

Image description

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!

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
alvlaskuri profile image
Alv Laskuri

Calculating the 6502 execution time involves understanding clock cycles and instruction timing, which are crucial for optimizing performance. While not directly related to ALV Laskuri, accurate calculations are essential in both computing and Finnish VAT (ALV) calculations, ensuring precision in financial and tax-related matters.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay