6502 Assembly Language Lab

In the world of technology, there's a certain allure to exploring the origins of computing, and what better way to embark on this quest than through experimentation? Today, we dive headfirst into the heart of a vintage marvel – the 6502 processor.

In this experiment, we are doing the performance tests of two bitmap code for 6502 processor. Both the test fill a 32*32 pixel screen with yellow color.

Code1:

1. Load the immediate value 00 into the accumulator register (A register).
2. Store the value from the accumulator register into the memory location $40.
3. Load the immediate value 02 into the accumulator register.
4. Store the value from the accumulator register into the memory location $41.
5. Load the immediate value 7 into the accumulator register.
6. Load the immediate value 0 into the Y register.
7. Store the contents of the accumulator (which is 7) into the memory address specified by the 16-bit pointer formed by combining the values at memory locations $40 and $41, plus the current value of the Y register (which is 0).
8. I
ncrement the Y register by 1. The Y register is often used as an index or offset in memory operations. 9. Continue looping until the Y register becomes zero. 10. Increment the value stored in memory location $41, which represents the high byte of the 16-bit pointer. 11. Loads the value from memory location $41 into the X register. 12. Compare the value in the X register with the immediate value 6. 13. Continue the loop until the X register contains a value equal to 6.

Based on the above calculations it takes  0.1716 seconds to fill the whole screen with yellow.

Code2:
1. Load the immediate value 07 into the accumulator register (A register).
2. Load the immediate value 0 into the Y register.
3. Store the contents of the accumulator (which is 7) into the memory address $0200.
4. Increment the Y register by 1.
5. Continue looping until the Y register becomes zero.
6. Repeat the 5th step (LOOP) 4 times. Each loop is for a new page.
Based on the above calculations it takes  0.1026 seconds to fill the whole screen with yellow which is faster than the first code.

Modifying the code:

1. Changing the screen color from yellow to light blue:

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

Change the LDA $07 which is for yellow color to LDA $e which is for light blue color.

2. Changing the screen color for each page:
LDA #$07
LDY #$00
LOOP1: STA $0200, Y
INY
BNE LOOP1
LDA #$08
LOOP2: STA $0300, Y
INY
BNE LOOP2
LDA #$09
LOOP3: STA $0400, Y
INY
BNE LOOP3
LDA #$13
LOOP4: STA $0500, Y
INY
BNE LOOP4

For each loop LDA $07 is being changed for different color.

Additional Experiments:
In the above experiment, the additional instruction tya after the loop label is loading the number from the Y register to the A register which is causing the color to change for each loop.

The addition of lsr after tya is performs a logical shift right on the accumulator. This effectively divides the value by 2 in the accumulator.

Walkthrough:
First iteration of TYA loads 00 in the accumulator from Y register which is for black.
Second iteration of TYA loads 01 in the accumulator from Y register and LSR performs a logical shift right on the accumulator which makes the accumulator 00 again.

In the above image, there is an additional lsr after tya. This new addition caused the width of each color to expand to three pixel.

Walkthrough:
First iteration of TYA loads 00 in the accumulator from Y register which is for black.
Second iteration of TYA loads 01 in the accumulator from Y register and LSR performs a logical shift right on the accumulator which makes the accumulator 00 again.
Third iteration of TYA loads 02 in the accumulator from Y register and LSR performs 2 logical shift right on the accumulator which makes the accumulator 00 again.

Similarly if we continue to add more LSR, the width of each color will keep increasing.

Comments

Popular posts from this blog

Project stage 2

Project Stage 1 Inspection

AArch64 and x86_64 assembler code