Lab 01
This post is about Lab 1 for SPO600 course at Seneca College.
In this lab, I am going to use 6502 emulator to learn Assembly code and how to optimize the code.
The above code is given to the students, and we are required to change the code to do some required tasks such as changing color of the Bitmapped display, or optimizing code.
1. Calculate how long it takes for the code to execute, assuming a 1 MHz clock speed.
2. Also calculate the total memory usage for the program code plus any pointers or variables
3. Find one or more ways to decrease the time taken to fill the screen with a solid colour. Calculate the execution time of the fastest version of this program that you can create. Challenge: the fastest version is nearly twice as fast as the original version shown above!
Version 1. Just decreasing the number of loops by adding hard coding.
In this way, you can further reduce the cycles. However, there is a limit because `STA ($nn), Y` is very expensive. And also, `STA ($nn), Y` is colouring a pixel, so you cannot reduce the number of execution of this colouring process.
As you can see from the picture below, it is faster but the improvement is not huge:
Version 2. Using cheaper code and reducing unnecessary loops, we can dramatically increase the speed.
4. Change the code to fill the display with light blue instead of yellow.
lda #$00 ;
sta $40 ;
lda #$02 ;
sta $41 ;
lda #$e ; Light Blue
ldy #$00 ;
loop: sta ($40),y ;
iny ;
bne loop ;
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
5. Change the code to fill the display with a different colour on each page.
lda #$00 ;
sta $40 ;
lda #$02 ;
sta $41 ;
lda #$02 ;
ldy #$00 ;
loop: sta ($40),y ;
iny ;
bne loop ;
inc $41 ;
ldx $41 ;
lda $41 ; Change the Color for the next page
cpx #$06 ;
bne loop ;
6. Make each pixel a random colour.
lda #$00 ;
sta $40 ;
lda #$02 ;
sta $41 ;
lda #$02 ;
ldy #$00 ;
loop: sta ($40),y ;
iny ;
lda $fe ; set a random color for the next pixel
bne loop ;
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
Comments
Post a Comment