DEV Community

Cover image for Lab 2 6502 Assembly language lab
Qzhang125
Qzhang125

Posted on • Updated on

Lab 2 6502 Assembly language lab

Hello, this is the lab 2 of SPO600.

Print the horizontal line

The first task in this lab that we are going to draw green line at the top and draw a blue line at the bottom.

LDA #05             ; Color Green code
          LDY #$00      ; Position Index on First Line

TOP: 
          STA $0200,Y   ; Store color into the current Pixel
          INY           ; Go to the next pixel

          CPY #32       ; Check if it gets to the pixel 32
          BNE TOP  ; If it didn't hit pixel 32 yet, keep going
Enter fullscreen mode Exit fullscreen mode

We load a green pixel and set the start position of y at #$00. Then we store the color into the current position and set a loop to check the value of Y. If Y reached the end of the top line which is #32 then jump out of the loop.
We used the same logic to draw another blue line at the bottom.

LDA #06                  ; Color Blue Code
        LDY #$00         ; Position Index on Last Line

BOTTOM: 
             STA $05E0,Y; Store color into the current Pixel
             INY        ; Go to the next pixel by increase the value of Y
             CPY #32    ; Check if it gets to the pixel 32
       BNE BOTTOM  ; If it didn't reach pixel 32 yet, keep looping

Enter fullscreen mode Exit fullscreen mode

Print the vertical line

In the second task we are going to print 2 vertical lines at each side the square.

    LDA #$00          
    STA $10
    LDA #$02
    STA $11
    LDY $00

LEFT: 
       LDA #$07     ; Set color Yellow
       STA ($10),Y

       LDA $10
       CLC
       ADC #$20
       STA $10

       LDA $11
       ADC #$00
       STA $11

       CMP #$06
       BNE LEFT
Enter fullscreen mode Exit fullscreen mode

First, we create 2 pointers to video memory and set them to $10 and $11.
Second, we set the loop. Inside of the loop, we set the yellow color and put it into the current pixel.
Next, we load the accumulator and clear the carry flag. Then we add $20 into the accumulator in order to increment each line in the screen vertically. After that, we store the value $10 into the memory.
Afterwards, we load the value of $11 into the accumulator and store contents and carry flags into the memory.
At the end, we compare the content of memory with the accumulator to ensure the lines reach to the last page. If not, continue the loop.
Same idea to draw the purple line.

       LDA #$1F 
       STA $10
       LDA #$02
       STA $11
       LDY $00

RIGHT: 
       LDA #$04     ; Set color Purple
       STA ($10),Y

       LDA $10
       CLC
       ADC #$20
       STA $10

       LDA $11
       ADC #$00
       STA $11

       CMP #$06
       BNE RIGHT
Enter fullscreen mode Exit fullscreen mode

And the result:
Image description

Top comments (0)