Lab 2 - Assembly Language Lab
I am writing a Lab 2 which is about the basics of the assembly language of 6502. For this lab I was given a piece of code, for which I have to modify the code or to calculate performance.
First of all, I was given the following 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
This code fills the bitmapped display with yellow color, each pixel of the display is showing yellow color. The result of code is:
Here is the result:
Calculating Performance:
Our first task was to calculate performance of the code. Here is the analysis of the code:
We assuming that CPU has 1 MHz clock speed. We calculated that code will have 11313 cycles, and it will be take 11.313 ms to execute.
Modifying the code:
Our second task is to modify the code so that we can fill the bitmap display with light blue color. we can achieve it by loading the accumulator with $e instead of $07 which is the color code for light blue. Here is the updated 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 #$e ; 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
And here is the result:
Second part of the task is to change the color for each quarter of the bitmap display. In order to change the color for each quarter we need to change the value of accumulator each time the the outer loop iterates meaning, we can do it by writing LDA $41 after the bne loop, which means each time the page is changed, meaning page is incremented, value of accumulator will change which will result into changing in color. Here is the updated 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 #$e ; 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) lda $41 ; changing the value of accumulator, will change the color inc $41 ; increment the page ldx $41 ; get the current page number cpx #$06 ; compare with 6 bne loop ; continue until done all pages
This was fun activity, it taught me a lot about 6502 emulator. It also taught to calculate the performance of the code and calculate execution time.
Comments
Post a Comment