Lab - 1: Exploring 6502 Assembly
Exploring 6502 Assembly: A Journey into Low-Level Programming
Introduction
Setting Up the 6502 Emulator
The first step in this lab was setting up the 6502 Emulator, which is available at http://6502.cdot.systems. Since the emulator does not save progress automatically, I followed the recommended practice of periodically saving my work. Using Git for version control proved to be an efficient way to manage my code changes and experiments.
Understanding the Bitmap Code
]The provided bitmap code fills the emulator’s display with a solid yellow color. Here’s the breakdown of how it works:
This loop iterates through the display memory, coloring each pixel yellow.
Performance Analysis
Execution Time Calculation
Given a 1 MHz clock speed, I calculated how long it takes for the program to execute:
The main loop executes 256 times per page.
Since there are six pages to fill, the loop runs 256 × 6 = 1536 times.
Each iteration consists of five key instructions (STA, INY, BNE, INC, LDX, and CPX), each with different cycle counts.
Summing up the cycles for each iteration and multiplying by 1536 gives the total execution time.
After careful calculations, the execution time was determined to be ~24.576 milliseconds.
Overall, the execution time calculation
- Clock Speed: 1 MHz
- Cycle Time: 0.000001 seconds (1 µs)
- Execution Time: 24,408 cycles × 0.000001 s = 24.408 ms
Memory Usage Calculation
- Program instructions (a few dozen bytes)
- Pointer variables ($40 and $41)
- Screen memory of 1.5 KB ($0200 to $0600)
This reduces instruction cycles and speeds up execution significantly.
We’ve taken our first steps into the fascinating world of 6502 assemblies, unravelling its core concepts and writing our very first program. But this is just the beginning! In the next post, we’ll dive deeper, modify our code, and experiment with new instructions to truly understand the power of low-level programming. Stay tuned—things are about to get even more exciting!
Comments
Post a Comment