Lab 2 - 6502 Assembly Language Lab

Hello, my name is Pat and this is my Lab 2 write-up for my Software Portability and Optimization course at Seneca. Guidelines for this lab can be found here. Short version of it is, I was given some 6502 assembly language code (included below) and given some tasks to do with that code. The code given is very simple and fills the display with the colour yellow by looping through all of the pixels on the display.

	lda #$00	; set a pointer at $40 to point to $0200
	sta $40
	lda #$02
	sta $41

	lda #$07	; colour number

	ldy #$00	; set index to 0

loop:	sta ($40),y	; set pixel at the address (pointer)+Y

	iny		; increment index
	bne loop	; continue until done the page

	inc $41		; increment the page
	ldx $41		; get the current page number
	cpx #$06	; compare with 6
	bne loop	; continue until done all pages

Part 1 - Calculating Performance

First step was to calculate how long it takes for the code to execute assuming a 1 MHz clock speed. I calculated it would take 11323 μs. The table below shows my work for this calculation. 

    cycles cycle count alt cycles alt count total  
               
  lda #$00 2 1     2  
  sta $40 3 1     3  
  lda #$02 2 1     2  
  sta $41 3 1     3  
               
  lda #$07 2 1     2  
               
loop: sta ($40),y 6 1024     6144  
               
  iny 2 1024     2048  
  bne loop 3 1020 2 4 3068  
               
  inc $41 5 4     20  
  ldx $41 3 4     12  
  cpx #$06 2 4     8  
  bne loop 3 3 2 1 11  
               
          Total: 11323 cycles
          CPU speed: 1 MHz
          uS per clock: 1  
          Time:  11323 uS

The next step was to find optimizations in this code, and then calculate the runtime, however I was unfortunately unable to find any optimizations.

Part 2 - Modifying the code

The first step of this part is to modify the code to fill the display with light blue instead of yellow. To do this I change line 6 from lda #$07 to lda #$0e. Full code is displayed below.

	lda #$00	; set a pointer at $40 to point to $0200
	sta $40
	lda #$02
	sta $41

	lda #$0e	; colour number

	ldy #$00	; set index to 0

loop:	sta ($40),y	; set pixel at the address (pointer)+Y

	iny		; increment index
	bne loop	; continue until done the page

	inc $41		; increment the page
	ldx $41		; get the current page number
	cpx #$06	; compare with 6
	bne loop	; continue until done all pages

Second step was to make each page of the display a different. To do this, I added 1 to the colour value every time the page changed. This is a somewhat simple approach, but it's drawbacks are that the colours display must all be consecutive according to the assembly languages listing. Some variance can be achieved by changing how much the value increments by (e.g. by 2 or 3) but not much. Code displayed below.

lda #$00	; set a pointer at $40 to point to $0200
	sta $40
	lda #$02
	sta $41

	lda #$07	; colour number

	ldy #$00	; set index to 0

loop:	sta ($40),y	; set pixel at the address (pointer)+Y

	iny		; increment index
	bne loop	; continue until done the page

	inc $41		; increment the page
	ldx $41		; get the current page number
	adc #$01

	cpx #$06	; compare with 6
	bne loop	; continue until done all pages

Part 3 - Experience with the lab

I enjoyed this lab. Figuring out how to make every page a different colour ended up being somewhat challenging, and I felt I ended up using a sort of "lazy" fix, as there is no option for customizing the colours on each page. Definitely could have tried using variables or something but I kept it simple. What I learned in the process was there is no equivalent increment command for a, like there is with x and y (inc and iny). The work around was simple but still that was interesting. Otherwise, to address the obvious elephant in the room, (or at least obvious to me and my professor who will be reading this) I am very behind in this course. I have skipped Lab 1 because it involves research and I am bad at research. I wish I could have spent more time on this lab so I could do the optional sections but that's not realistic, and even then I wasn't able to find any optimizations in the code for Part 1, and that wasn't optional. I spent quite a bit of time trying to find a way to optimize it, but in the end I gave up because I really do need to start moving on in this course. 





Comments

Popular posts from this blog

SPO600 - Final Thoughts

SPO600 Project - Stage 1: Selection

Lab 4 - 64-bit Assembly Language Lab - Part 4