Improve Lab 2

In this post, I will enhance the Lab 2. The previous work can be found here.

This post will cover two main parts:

    1. Improving the calculation performance.

    2. Sharing experiences and reflections


Improving the calculation performance

Detailed information about the calculation performance can be found in this post.

Following the professor's feedback, it was identified that the previous fast version had a issue that it destroys all memory. Consequently, I have updated the code.

To reduce the execution time, the iterated part(loop) should be used as minimum as possible.

Each sta ($40), y command that utilizes indirect indexed addressing is repeated a total of six times. Instead of using indirect indexed addressing, replacing it with absolute addressing might significantly reduce the execution time.

The following is the code with the applied changes.

        lda #$07    
        ldy #$00    

loop:   sta $0200,y 
        iny 

        sta $0300,y    
        iny

        sta $0400,y  
        iny    

        sta $0500,y 

        bne loop

Based on the code, I calculated the execution time.

CyclesCycle CountAlt CyclesAlt CountTotal
lda #$07212
ldy #$00212
loop:sta $0200,y52561280
iny2256512
sta $0300,y52561280
iny2256512
sta $0400,y52561280
iny2256512
sta $0500,y52561280
bne loop4255211022
Total:7682cycles
CPU Speed:1MHz
uS per clock:1
Time:7682uS
7.682mS
0.007682S

Considering that the original version took 11.299 ms, it can be observed that this method has been effective in reducing the execution time.


Sharing experiences and reflections

Through my exploration of 6502 assembly language, I focused on optimizing code for better performance, particularly in the context of filling the emulator's display with a specific color. Analyzing cycle counts and execution times, I attempted to streamline the code, leading to a moderate improvement from the original 11.331 milliseconds to 11.299 milliseconds. This process deepened my understanding of how each instruction contributes to overall performance.
In parallel, color manipulation experiments were conducted, including changing the primary color from yellow to light blue and experimenting with different color sequences on each display page. Introducing color variations and employing bitwise operations like logical shift right (lsr) added visual differences, providing insights into color representation nuances in 6502 assembly language. While working with assembly language presented challenges, such as optimizing code without compromising functionality, these hurdles became opportunities for enhancing problem-solving skills and code optimization strategies.

Comments

Popular posts from this blog

Project - Stage 2 (Part 1)

Understanding Docker: A Comprehensive Guide

Project - Stage 1