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         


















7. Review

First time when I saw lab 1 and the Assembly code, I seriously considered dropping course. It was overwhelming. However, after I studied the Assembly code for hours and finally understood how it works. And also it's really fun thinking about the cycles and how to reduce the cyles even if it is just a few cycles. This lab was very tough but interesting.

Comments

popular posts in this blog

Project Stage 2 - part 2 : Clone-Pruning Analysis Pass

Project Stage 2 part 4 - Testing clone-test-core.c file with Modified GCC file and making further modification

Project Stage 2 part 3 - Compile a program with revised GCC