Lab-1: Exploring 6502 Assembly

Introduction

This lab focuses on using the 6502 emulator to understand assembly language by manipulating a bitmapped display. The goal is to fill the screen with colors, optimize the code for better performance, and experiment with various modifications to observe visual effects. Through this lab, we learn about addressing modes, loop structures, and how execution time and memory usage are calculated in a 6502-based system.

Performance Analysis
We used an online 6502 emulator since physical hardware wasn't available. The lab required analyzing and manipulating an initial code sample to achieve specific objectives. Here's the original code:


At first glance, this sequence of instructions seems daunting. However, once broken down, it becomes quite logical. The code fills a 1024-pixel bitmap display with yellow (color code #$07) by iterating through all four 256-byte pages of the display.

Below is the output from the emulator after running this code:


Task 1: Calculate Execution Time 

To determine how long the program takes to execute with a 1 MHz clock speed, I analyzed the number of cycles each instruction uses and the number of times it is executed. Here's a breakdown:





Task 2: Memory Usage

This task was easy as in the emulator it shows how many bytes it uses. Still I counted it in the above image. 



Task 3: Optimizing Performance

To make the program faster, I leveraged the fact that all pages can be iterated independently. Instead of handling one page at a time, I updated all pages simultaneously. Here's the optimized code:





As we can see, when I changed the code to run for each page together the speed decreased drastically.

Task 4: Fill the Display with Light Blue
To change the fill color, I simply replaced "lda #$07 with lda #$0e" (light blue color code):



Task 5: Different Colors for Each Page

For this task, I modified the program to load a different color for each page. Here's the updated code:





Task 6: Random Pixel Colors

Using lda $fe, I generated random colors for each pixel:


Conclusion

This lab provided a hands-on introduction to assembly programming, highlighting the importance of understanding hardware-level operations. Tasks like optimizing performance and experimenting with visuals were both challenging and rewarding. Assembly programming has deepened my appreciation for how computers execute low-level instructions, and I look forward to future labs to build on this foundation.

Comments

Popular posts from this blog

Project Stage III: Multi-Clone Analysis in GCC Pass

Lab 2 - 6502 Math Lab