Lab 1: Mob Programming with 6502 Emulator
Introduction
In this lab, we explored Mob Programming using the 6502 Emulator. Mob Programming is an extension of Pair Programming where the entire team works on the same code simultaneously, with one person acting as the “Driver” and others providing input and reviewing the code. This exercise involved collaborative coding, understanding assembly language, and optimizing code performance.
Performing the Lab
Initial Setup
We formed groups and assigned roles:
- Driver: The person typing the code.
- Presenter: The person presenting the group’s results to the class.
We decided to share code using a Git repository to ensure everyone had access to the latest version.
Bitmap Code
We used the following code to fill the emulator’s bitmapped display with yellow:
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 ; colour number
ldy #$00 ; set index to 0
loop:
sta ($40),y ; set pixel colour 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
Calculating Performance
Execution Time Calculation
We calculated the execution time assuming a 1 MHz clock speed:
lda takes 2 cycles.
sta takes 4 cycles.
iny takes 2 cycles.
bne takes 2 cycles (when branching) or 3 cycles (when not branching).
inc takes 5 cycles.
ldx takes 3 cycles.
cpx takes 2 cycles.
The total execution time was calculated by estimating the number of iterations and summing the cycles for each instruction.
Optimizing the Code
We optimized the code to reduce execution time. Here’s an optimized version:
lda #$07
ldy #$00
ldx #$00
sty $40
stx $41
fill_screen:
sta ($40),y
iny
bne fill_screen
inc $41
cpx #$05
beq done
bne fill_screen
done:
This version reduces execution time by streamlining the loop and eliminating unnecessary instructions.
Modifying the Code
Change to Light Blue
We modified the code to fill the display with light blue:
lda #$0F ; colour number for light blue
ldy #$00
loop:
sta ($40),y
iny
bne loop
inc $41
ldx $41
cpx #$06
bne loop
Different Colour per Page
We changed the code to fill each page with a different color:
lda #$00 ; set initial colour
ldy #$00
page_loop:
sta ($40),y
iny
bne page_loop
inc $41
lda $41
adc #$01 ; increment colour
sta $40
cpx #$06
bne page_loop
Reflections
This lab provided a hands-on experience with Assembly Language, allowing us to understand low-level programming concepts and performance optimization. Through collaborative Mob Programming, we effectively shared knowledge and tackled challenges together. The experiments deepened our understanding of how assembly instructions affect the display, and the challenges pushed us to think creatively.