Thursday, January 16, 2020
Lab 2: Assembly Language
Introduction
This post will cover my findings and overall thoughts regarding the lab I performed on Monday January 13, 2020. My findings on the bitmap code experiments as well as the results from the "writing code" segment will be covered.
Bitmap Code Results
After we copied the provided code onto the 6502 emulator we first added the statement "tya" after "sta ($40), y". The results I noticed were that there were 16 different colours and each colour occupied a column of the screen stretching down to the bottom. I believed this occurred because instead of using the predefined colour from the line "lda #$07" we instead used the incremented value in the y register as the value defining the colour. I think there were only 16 unique colours as that is the limit on amount of different colours and because we incremented the y register we essentially gone through all of them.
The next task my group did was to add the statement "lsr" after the "tya" statement we added earlier. The results were that there were less columns than before and the columns that did show up were much thicker. This was because by adding the "lsr" statement we are making each colour value last longer. For instance, without the "lsr statement" the value for blue would only last 1 pixel but by adding "lsr" the blue value would last 2 pixels. We also tried adding multiple "lsr" statements what I noticed were that less and less colours were present. As well as that if there are multiple "lsr" statements the columns would not longer stretch down to the bottom of the screen.
The test we did after was to replace the added "lsr" statements with "asl". The results were that even less colours showed up compared to when we added "lsr". Another finding was that if we added four or more "asl" statements the screen would just turn black. This was because with each time we added "asl" we were potentially increasing the colour values by 2, 4, or even 8 in each loop iteration.
The final experiment we did as a group was to remove all of the "asl" statements and add multiple "iny" lines after the original one. The findings were that if we had an even number of "iny" lines a stripe pattern would appear. But if there were an odd amount of "iny" lines then a checkerboard like animation would play and the screen would eventually be fully covered. I think this is because the more you increase the value in the y register the more you push out the position of the next pixel.
Writing Code, Part 1
Code:
; draw a green line across the top
; Set the starting position of the line
lda #$00 ; position pt2
sta $40
lda #$02 ; position pt1
sta $41
lda #$5 ;set the colour of the pixel
ldy #$00 ; set the index
topLineLoop: sta ($40),y
iny
cpy #32
bmi topLineLoop
; draw a blue line across the bottom
; Set the starting position of the line
lda #$e0 ; position pt2
sta $50
lda #$05 ; position pt1
sta $51
lda #$6 ; set the colour
ldy #$00 ; set the index
bottomLineLoop: sta ($50), y
iny
cpy #32
bmi bottomLineLoop
The way the code works essentially is that first I set the position of the first pixel in the line. Afterwards I start incrementing the value of the y register until I reach a certain threshold. This is so that I only draw pixels until a certain point is reached. The results were that a yellow line was drawn at the top and a blue line was drawn at the bottom.
Writing Code, Part 2
Code:
; draw a yellow line down the left side
; set the starting position of the line
lda #00 ; position pt2
sta $60
lda #$02 ; position pt1
sta $61
lda #$7 ; set the colour
ldy #$00
sty $63
leftLineLoop: ldx #0
sta ($60), y
leftPush: ; set the position of the next pixel to be 32 units ahead
inx
iny
cpx #32
bne leftPush
cpy $4AA
bne leftLineLoop
inc $61 ;increment the page
ldx $61 ;store the page
cpx #$06 ; see if the page is not = $#06
bne leftLineLoop
; draw a purple line down the right side
; set the starting position of the line
lda #31 ; position pt2
sta $70
lda #$02 ; position pt1
sta $71
lda #$4 ; set the colour
ldy #$00
sty $73
rightLineLoop: ldx #0
sta ($70), y
rightPush: ; set the position of the next pixel to be 32 units ahead
inx
iny
cpx #32
bne rightPush
cpy $4AA
bne rightLineLoop
inc $71 ;increment the page
ldx $71 ;store the page
cpx #$06 ; see if the page is not = $#06
bne rightLineLoop
brk
The code works like first "writing code" segment but this time within the drawing loop there is another loop that pushes the position of the next pixel by a certain number of units. For instance, when drawing the yellow line on the left side I would push the position of the next pixel by 32 units so that on the next iteration of the loop the next pixel would be below the previous yellow pixel. Another difference is that I increment through the pages. This is so that its easier to go down the screen when drawing.
Conclusion
Overall my impressions on the assembly language is that even though its fascinating and satisfying to make something out of it. The amount of micromanagement and obscurity in the language makes my appreciate higher level languages like C++ even more. As they let me focus more on ideas and less on the deep level nuts and bolts. The main idea I learned from this lab is that where you move numbers and how you modify them can have a great impact on the results of your code. In terms of the process the main takeaway is that its a matter of constantly iterating. As this is new material to me and the best way to progress was to constantly try out different bits of code and see what comes from it.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment