SPO600 Lab 2 - 6502 Assembly Language
In this post, I will discuss my first Assembly code experience. I will calculate and enhance the running time of a provided code and optimize it so its execution time is shortened. I will also perform some experiments on the provided code by modifying parts of it and showing the output.
Introduction
First, I will show you the provided Assembly code and its output. I ran the code using the 6502 Assembly simulator which you can access here.
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 ; 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
OUTPUT:
Calculating Performance
I will calculate the execution speed of the code assuming the the clock speed is 1 MHz.
As per the calculation above, the total execution time of the given code is 2,588 microseconds.
I will now calculate the total memory usage of the program including variables and pointers.
With all the instructions, variables, and pointers taken into account, the total memory usage of the program is 36 bytes.
Optimizing Provided Code
I tried to play around with the code and instructions, however, due to my unfamiliarity with Assembly language, I was not able to decrease the execution time and optimize the provided code.
Code Modifications
In the code below, I modified line 4 to fill the screen with cyan instead of yellow. I simply change the color number to 3 instead of 7.
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 #$03 ; colour number changed to 3 for cyan 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
Comments
Post a Comment