6502 Assembly Language Lab
Lab 2
Tim Lin
2. This week the professor let us practice using the 6502 simulators. Run 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
4. Calculate how long it takes for the code to execute.
6. Change the code to fill the display with light blue instead of yellow.
lda #$07 change to lda #$e
lda #$00 ;
sta $40 ;
lda #$02
sta $41 ;
lda #$e ;
ldy #$00 ;
loop: sta ($40),y ;
iny ;
bne loop ;
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
7. Change the code to fill the display with a different colour on each page.
Add "lsr" under bne loop
lda #$00 ;
sta $40 ;
lda #$02
sta $41 ;
lda #$07 ;
ldy #$00 ;
loop: sta ($40),y ;
iny ;
bne loop ;
lsr
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
Experiments
2. After adding "tya", there are 11 colors on the screen. Because instruction tya means ‘Transfer Y to A’ it is one of the instruction for Transferring Data between Registers.
3. Add this instruction after the
tya
: lsa
lda #$00 ;
sta $40 ;
lda #$02
sta $41 ;
lda #$e ;
ldy #$00 ;
loop:
tya:
lsr
sta ($40),y ;
iny ;
bne loop ;
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
lda #$00 ;
sta $40 ;
lda #$02
sta $41 ;
lda #$e ;
ldy #$00 ;
loop:
tya:
lsr
lsr
lsr
lsr
sta ($40),y ;
iny ;
bne loop ;
inc $41 ;
ldx $41 ;
cpx #$06 ;
bne loop ;
6. If using one "asl". It will display Vertical 8-color block.
8. "iny" experiment:
one "iny" : Fill in the colour blocks from top to bottom, left to right, row by row.
two "iny" : Fill in the colour blocks from top to bottom, left to right, row by row, but two columns of blocks will be lost.
three "iny": Small colour blocks will be filled one by one, not all at once.
four "iny": Only 6 columns of colour blocks will be displayed.
five "iny": Same as one "iny".
Reflections
In this lab I learned to compute the performance, I followed the video to understand the computational process and principles. Then I learned exactly what the code does. I modified my code with the commands in the example and its colour changed. I learned a lot about colour blocking.
Comments
Post a Comment