Lab 02: 6502 Assembly Language Lab

Paste this code into the emulator:
 lda #$00 ; set a pointer at $40 to point to $0200
 sta $40
 lda #$02
 sta $41

 lda #$07 ; colour

 ldy #$00 ; set index to 0

loop: sta ($40),y ; set pixel

 iny  ; increment index
 bne loop ; continue until done the page

 inc $41  ; increment the page
 ldx $41  ; get the page
 cpx #$06 ; compare with 6
 bne loop ; continue until done all pages

 Add this instruction after the loop: label and before the sta ($40),y instruction:
 tya
What visual effect does this cause, and how many colours are on the screen? Why?
Answer: The bitmap would display columns of 16 colors repeating once. 
The reason is because we use "lda #$07" to load accumulator "a" as our designated color, when  we add "tya" at the start of our loop, we transfer "y" to "a". So as "y" increment, so does our color "a". And since the max number of "y" we have is 32, it would repeat the color once within the row.
Add this instruction after the tya:
 lsr
What visual effect does this cause, and how many colours are on the screen? Why?
Answer: The bitmap would display wider columns of 16 color without repeating.
The reason is because "lsr" represents "Logic shift right". When we integrated "lsr" into our loop, we are basically dividing our "y" by 2 each time it increments. And since our compiler rounds down, it would have a "y" increment of the following "0, 0, 1, 1, 2, 2, ....... instead of the normal "0, 1, 2, 3,.....". And since the color is set with the "y" increment, every two loop would repeat the same color, thus it won't repeat the pattern within the row .
Repeat the above tests with two, three, four, and five lsr instructions in a row. Describe and explain the effect in each case.
Answer: The bitmap would display the 16 colors, but not all within one row.
The reason is because as we add more "lsr" into our loop, we continue to repeat the color more before displaying the next one. This would delay the change of colors more into the next row instead of displaying them all within one.
Repeat the tests using asl instructions instead of lsr instructions. Describe and explain the effect in each case.
Answer: The bitmap would display some skipped of 16 colors.
The reason is because "asl" represent "Arithmetic shift left". Which is multiplying our "y" by 2 each time it increments, it would be "0, 2, 4, 6, ......" instead of the normal "0, 1, 2, 3, ....", And since the color is set with the "y" increment, every loop would skip a color.
More color would be skipped as well if we include additional "asl".
Remove the tya and all asl and lsr instructions.
The original code includes one iny instruction. Test with one to five consecutive iny instructions. Describe and explain the effect in each case. Note: ensure that the Speed slider is on its lowest setting (left) for these experiments.
Answer: The bitmap would be filled by original color (yellow) based on how many "iny" we includes.
The reason is because each row has 32 pixels, as we run through each loop it will fill the "y" designation with yellow. And if we put additional "iny", it would increment "y" one more, thus skipping some of the pixel not filled.

Write code to draw a green line across the top of the bitmap screen and a blue line across the bottom.

Answer:
lda #$00 ; set a pointer at $40 to point to $0200
sta $40
lda #$02
sta $41

lda #$0d ; green
ldy #$00 ; index

top:
sta $0200,y ; draw pixel
iny ; increment y
cpy #$20 ; compare y with $20 
bne top ; if y != $20, exit loop

lda #$0e ; blue
ldy #$00 ; index

bot:
sta $05e0,y ; draw pixel
iny ; increment y
cpy #$20 compare y with $20

bne bot ; if y != $20, exit loop

Extend the previous code to draw a yellow line down the left side of the screen and a purple line down the right side.
Answer: 
lda #$00 ; set a pointer at $10 to point to $0200
sta $10
lda #$02
sta $11

ldy #$00 ;index

left:
lda #$07 ; yellow
sta ($10),y ; draw pixel 
lda $10
clc
adc #$20
sta $10

bcc left
inc $11
lda $11
cmp #$06
bne left

lda #$1f
sta $10
lda #$20
sta $11

ldy #$00

right:
lda #$04 ; purple
sta ($10),y ; draw pixel
lda $10
clc
adc #$20
sta $10

bcc right
inc $11
lda $11
cmp #$06

bne right

Comments

Popular posts from this blog

Lab 01: Code Review

Course Project Stage 2 Introduction

Course Project Stage 2 part 2: Profiling