SPO600 - LAB 1: 6502 - Assembly Language Lab (Part 2) and Reflection
This blog discusses my experience with the 6502 assembly language through a series of experiments aimed at manipulating a bitmap display. In this lab, I investigated the effects of various assembly instructions on screen output, focussing on how shifting and incrementing values alter the colours displayed. I also completed additional challenges such as changing specific pixels to different colours and drawing lines around the screen's edge.
Experiment
1. Add tya Before sta ($40),y
The first experiment involves placing the tya instruction before the sta ($40),y. This transfers the value from the Y register to the A register, which determines the colour used to fill the screen.
2,
For each pixel, iny increments the Y register, and with tya, the value in the Y register is copied into the A register. The A register controls the pixel colour in the sta ($40),y instruction, so the screen is filled with colours based on the value of Y.
This means that the colour of each pixel is directly proportional to the Y value, resulting in a gradient effect across the screen, beginning with the lowest Y value at the top and progressing to the highest at the bottom.
I saw 16 distinct colors because only the lower 4 bits of the Y register is used for color.
3. Ading lsr After tya
I included the lsr instruction after tya. This shifts the bits in A to the right, effectively dividing its value (and thus Y) by two.
The right shift operation causes the colour to change more slowly, resulting in fewer distinct colours on the screen (because the value of A is reduced by half).
4.
The lsr instruction shifts the bits in A to the right, effectively halving its value. This limits the number of possible colours because some of the lower bits of the Y value are lost.
As a result, the screen had fewer distinct colours than if only tya is used. The colour gradient appeared less smooth as a result of the shift operation, which reduces many smaller colour variations.
Number of colours:
After one lsr, the number of distinct colours is reduced by half. The original system had 16 colours (based on 4 bits), I now only see 8.
5. Adding Multiple lsr Instructions
I repeated the experiment with two, three, four, and five lsr instructions in succession to see how additional shifting affects the display.
Add Two lsr Instructions
With two lsr
instructions, the value of A is shifted right twice, meaning the value is now divided by 4. This reduce the number of distinct colors even further, resulting in wider bands of the same color across the screen.
The color transitions is even smoother, but with fewer color changes between each band.
Add three lsr Instructions
Three lsr instructions move the value of A to the right three times, dividing it by eight. This means that even fewer colours appear on the screen. The colour bandsbe significantly larger, with each colour taking up more screen space.
Four lsr instructions shift the value of A right four times, dividing it by 16. At this point, I only saw one colour on screen.
Five lsr instructions cause the value of A to be shifted right five times, resulting in a division by 32. This further reduces the number of colours.
6. Replacing lsr with asl
Next, I replaced the lsr instruction with asl (arithmetic shift left), which moves the bits in A to the left, effectively doubling its value.
The screen transitioned colours more quickly. The colour values increased rapidly, resulting in a faster gradient and more frequent colour changes across the display.Shifting left by one bit doubles the value in A, causing the colours to change faster across the screen. The colour bands will become narrower as the value increases at a faster rate.
The screen is likely to cycle through colours faster, with more rapid transitions.
Effect of Two Asl: Shifting left twice multiplies the value in A by four. The colours change even faster across the screen, creating a more rapid cycling effect.
Effect of Three asl: Three shifts multiply the value by 8, causing the screen to display even faster colour transitions and very narrow colour bands.
Number of colours:
The number of colours remains constant (depending on the system's colour depth), but colour transitions occur more quickly because the value in A increases faster.
7. Revert to the original code
8. Testing Multiple iny Instructions
I experimented with using multiple iny instructions in a row. Each additional iny instruction increases the Y register by one, so multiple iny instructions result in more pixels skipped in each loop.
Adding more iny instructions caused the program to skip pixels, resulting in fewer coloured pixels but more space between them. This experiment demonstrated how adjusting the Y register's increment rate affects the density of coloured pixels on the screen.
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 $FE ; Sets random colour (number) to accumulator ldx #$06 ; get the current page number ldy #$00 ; set index to 0 loop: STA ($40), y iny BNE loop inc $41 ; increment the page cpx $41 ; compare current page to x (0600) bne loop ; continue until done all pages ADC #$01 ; Add one to the colour code STA $03EF ; Storing the new coloured pixels at middle location STA $03F0 STA $040F STA $0410
My solution to this challenge was to manually add each of the middle pixel locations and assign them +1 to the colour chosen
This lab not only helped me improve my problem-solving skills, but it also taught me to think more critically about resource management, memory, and programming efficiency.
Nhận xét
Đăng nhận xét