LAB 01

 


Exploring Assembly Language with the 6502 Emulator: Lab 1

In this lab, I explored programming on the 6502 Emulator, which simulates the 6502 microprocessor. My objective was to fill a bitmapped display with colors, analyze the program's performance, and implement creative patterns. This lab offered an opportunity to understand low-level Assembly Language programming and optimize performance.

The primary objectives were to:

  • Fill the display with colors.
  • Optimize code for performance.
  • Experiment with patterns and behaviors on the screen.

Tasks and Observations==>

  1. Original Bitmap Code
    lda #$00 ; set a pointer in memory location $40 to point to $0200
    sta $40 ; low byte ($00) goes in address $40
    lda #$02
    sta $41 ; high byte ($02) goes into address $41
    lda #$07 ; color number (yellow)
    ldy #$00 ; set index to 0
    loop:
    sta ($40),y ; set pixel color at the address (pointer)+Y
    iny ; increment index
    bne loop ; continue until done the page (256 pixels)
    inc $41 ; increment the page
    ldx $41 ; get the current page number
    cpx #$06 ; compare with 6
    bne loop ; continue until done all pages

    Result:
    This code successfully filled the entire screen with yellow. The program utilized nested loops to iterate through every pixel address in memory. While effective, this version was not optimized for speed.

2. CALCULATE PERFORMANCE

To calculate the program's execution time:

  1. The inner loop runs 256 iterations per page.
  2. There are 4 pages in the display, resulting in 1024 iterations.
  3. Each instruction takes a fixed number of CPU cycles. Summing the cycles for all instructions within the loop gave a total execution time of approximately 96 milliseconds on a 1 MHz clock.
  4. Memory Usage: The code used 25 bytes for the program and additional memory for pointers and variables.
This image has an empty alt attribute; its file name is image.png

3. Experiments

a) Experiment 1: (Adding tya)By adding tya before sta ($40),y, the value of the Y register was written directly as the color. This created a gradient effect as the Y value incremented.


This image has an empty alt attribute; its file name is image-2.png


b) Experiment 2: (Using lsr) Adding lsr after tya caused a bit-shift operation, reducing the intensity of the colors. With multiple lsr instructions, the gradient became more subdued.
c) Experiment 4: (Consecutive iny Instructions)Adding 2-5 consecutive iny instructions increased the spacing between pixels, forming a dotted pattern across the screen.

4.Custom Pattern

Center Pixels in a Different Color

This program filled the screen with yellow but used light greyish for the center pixels

This image has an empty alt attribute; its file name is screenshot-2025-01-12-153653.png

5. Reflection:

This lab was a rewarding dive into Assembly Language programming. Working with the 6502 Emulator gave me a deeper understanding of how low-level operations control hardware. Optimizing the code was challenging but taught me the importance of efficient programming in constrained environments. The experiments and creative challenges added a fun, artistic element to the lab.

I’ve gained valuable insights into:

a) How small instructions can create visually compelling effects.

b) Memory addressing and looping in Assembly.

c) Code optimization techniques.

Comments

Popular posts from this blog

Project Stage 1: Create a GCC pass

LAB 03

Project Stage 2: Part 2( The End)