Lab 1

 

6502 Assembly Language Lab


In this lab, I explored the 6502 Emulator to manipulate the bitmapped display using assembly language. The goal was to fill the screen with colors, experiment with random pixel values, and optimize execution time.


Task 1: Filling the Screen with Yellow

The initial code filled the screen with a solid yellow color. Here's the snippet:


lda #$00 ; Set a pointer in memory location $40 to point to $0200 sta $40 ; Low byte ($00) in address $40 lda #$02 sta $41 ; High byte ($02) in address $41 lda #$07 ; Yellow color code ldy #$00 ; Set index to 0 loop: sta ($40),y ; Set pixel color at address (pointer)+Y iny ; Increment index bne loop ; Continue until the page is filled inc $41 ; Increment page ldx $41 ; Get current page number cpx #$06 ; Compare with 6 bne loop ; Continue until all pages are filled



Execution Time Calculation

  • Each pixel requires 11 cycles (6 cycles for sta, 2 cycles for iny, 3 cycles for bne).
  • For 256 pixels: 11×256=281611 \times 256 = 2816 cycles per page.
  • For 4 pages: 2816×4=112642816 \times 4 = 11264 cycles.

At a clock speed of 1 MHz: 

Execution Time = 11264 cycles/1000000 cycles per sec = 0.011264 Seconds


To reduce execution time, I explored alternatives like replacing loops with unrolled code segments and optimizing memory access patterns, I nearly halved the execution time. The final optimized code executed in approximately 0.006seconds.


Change to Light Green: Replacing the color code (#$07) with #$0D resulted in a light green display:


lda #$0D ; Light green sta ($40),y ; Set color




Different Colors per Page: Modified the loop to use a different color code (#$07, #$0B, etc.)


lda #$07 ; Yellow for the first page sta ($40),y inc $41 ; Move to the next page lda #$0B ; Light blue for the next page sta ($40),y

Random Colors per Pixel: Using the pseudo-random number generator provided:


jsr random ; Generate random number sta ($40),y ; Use random number as the color




Reflection

In this lab, I learnt that small changes had a significant impact on performance, debugging in assembly requires careful attention because even subtle errors can be very impactful.


Comments

Popular posts from this blog

Building GCC Part 2

Wrapping Up Project : Stage 3