1,885
edits
Changes
Created page with "<!-- {{Chris Tyler Draft}} --> Category:SPO600 Labs{{Admon/lab|Purpose of this Lab|In this lab, you will learn some of the basics of 6502 assembly language, in prepara..."
<!-- {{Chris Tyler Draft}} -->
[[Category:SPO600 Labs]]{{Admon/lab|Purpose of this Lab|In this lab, you will learn some of the basics of [[6502]] assembly language, in preparation for learning more complex x86_64 and AArch64 assembly language.}}
This is a lab for the [[SPO600]] course.
== Resources ==
* [[6502]] Wiki Page
* [[6502 Emulator]]
* [[6502 Emulator Example Code]]
* Opcode/Instruction References
** [http://www.6502.org/tutorials/6502opcodes.html 6502 Opcodes with Register Definitions]
** [https://www.masswerk.at/6502/6502_instruction_set.html 6502 Opcodes with Detailed Operation Information]
== Lab 1 ==
=== Setup ===
1. Open the [[6502 Emulator]] at http://6502.cdot.systems in another tab or window, keeping this lab open.
{{Admon/important|Save Your Work|The emulator '''does not''' save your work automatically. Remember to periodically save it to a file (copy-and-paste the code or use the <code>Save</code> button).}}
=== Bitmap Code ===
2. The following code fills the emulator's bitmapped display with the colour yellow. 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 number
ldy #$00 ; set index to 0
loop: sta ($40),y ; set pixel at the address (pointer)+Y
iny ; increment index
bne loop ; continue until done the page
inc $41 ; increment the page
ldx $41 ; get the current page number
cpx #$06 ; compare with 6
bne loop ; continue until done all pages
3. Test the code by pressing the Assemble button, then the Run button. If the there are any errors assembling (compiling) the code, they will appear in the message area at the bottom of the page. Make sure the code is running correctly and that you understands how it works.
=== Calculating Performance ===
4. Calculate how long it takes for the code to execute, assuming a 1 MHz clock speed.
around
5. Consider ways to decrease the time taken to clear the screen. Calculate the execution time of the fastest version of this program that you can create.
=== Modifying the Code ===
6. Change the code to fill the display with light blue instead of yellow. (Tip: you can find the colour codes on the [[6502 Emulator]] page).
7. Change the code to fill the display with a different colour on each page (each "page" will be one-quarter of the bitmapped display).
=== Experiments (Optional, Recommended) ===
Go back to the bitmap code above, and try these experiments:
# Add this instruction after the <code>loop:</code> label and before the <code>sta ($40),y</code> instruction: <code>tya</code>
# What visual effect does this cause, and how many colours are on the screen? Why?
# Add this instruction after the <code>tya</code>: <code>lsa</code>
# What visual effect does this cause, and how many colours are on the screen? Why?
# Repeat the above tests with two, three, four, and five <code>lsr</code> instructions in a row. Describe and explain the effect in each case.
# Repeat the tests using <code>asl</code> instructions instead of <code>lsr</code> instructions. Describe and explain the effect in each case.
# Revert to the original code.
# The original code includes one <code>iny</code> instruction. Test with one to five consecutive <code>iny</code> instructions. Describe and explain the effect in each case. '''Note:''' it is helpful to place the Speed slider is on its lowest setting (left) for these experiments.
# Revert to the original code.
# Make each pixel a random colour. (Hint: use the psudo-random number generator mentioned on the [[6502 Emulator]] page).
=== Challenges (Optional, Recommended) ===
# Set all of the display pixels to the same colour, except for the middle four pixels, which will be drawn in another colour.
# Write a program which draws lines at the top and bottom of the display:
#* A red line across the top
#* A green line across the bottom
== Write-Up ==
Post an entry on your blog describing your experiments in this lab. Follow the [[Blog Guidelines]]. Include code as text (and not screenshots), but feel free to include screenshots of the bitmapped display.
Include in your blog post:
# An introduction, so that someone who happens across your blog will understand the context of what you're writing about.
# The results from the ''Calculating Performance'' and ''Modifying Code'' portions of the lab, including the code, a description of how the code works, and the results produced.
# The results of the Optional sections, if you performed them, and your explaination for each observed result.
# Your experiences with this lab -- your impressions of Assembly Language, what you learned, and your reflections on the process.
Remember to follow the [[Blog Guidelines]] as you write.
[[Category:SPO600 Labs]]{{Admon/lab|Purpose of this Lab|In this lab, you will learn some of the basics of [[6502]] assembly language, in preparation for learning more complex x86_64 and AArch64 assembly language.}}
This is a lab for the [[SPO600]] course.
== Resources ==
* [[6502]] Wiki Page
* [[6502 Emulator]]
* [[6502 Emulator Example Code]]
* Opcode/Instruction References
** [http://www.6502.org/tutorials/6502opcodes.html 6502 Opcodes with Register Definitions]
** [https://www.masswerk.at/6502/6502_instruction_set.html 6502 Opcodes with Detailed Operation Information]
== Lab 1 ==
=== Setup ===
1. Open the [[6502 Emulator]] at http://6502.cdot.systems in another tab or window, keeping this lab open.
{{Admon/important|Save Your Work|The emulator '''does not''' save your work automatically. Remember to periodically save it to a file (copy-and-paste the code or use the <code>Save</code> button).}}
=== Bitmap Code ===
2. The following code fills the emulator's bitmapped display with the colour yellow. 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 number
ldy #$00 ; set index to 0
loop: sta ($40),y ; set pixel at the address (pointer)+Y
iny ; increment index
bne loop ; continue until done the page
inc $41 ; increment the page
ldx $41 ; get the current page number
cpx #$06 ; compare with 6
bne loop ; continue until done all pages
3. Test the code by pressing the Assemble button, then the Run button. If the there are any errors assembling (compiling) the code, they will appear in the message area at the bottom of the page. Make sure the code is running correctly and that you understands how it works.
=== Calculating Performance ===
4. Calculate how long it takes for the code to execute, assuming a 1 MHz clock speed.
around
5. Consider ways to decrease the time taken to clear the screen. Calculate the execution time of the fastest version of this program that you can create.
=== Modifying the Code ===
6. Change the code to fill the display with light blue instead of yellow. (Tip: you can find the colour codes on the [[6502 Emulator]] page).
7. Change the code to fill the display with a different colour on each page (each "page" will be one-quarter of the bitmapped display).
=== Experiments (Optional, Recommended) ===
Go back to the bitmap code above, and try these experiments:
# Add this instruction after the <code>loop:</code> label and before the <code>sta ($40),y</code> instruction: <code>tya</code>
# What visual effect does this cause, and how many colours are on the screen? Why?
# Add this instruction after the <code>tya</code>: <code>lsa</code>
# What visual effect does this cause, and how many colours are on the screen? Why?
# Repeat the above tests with two, three, four, and five <code>lsr</code> instructions in a row. Describe and explain the effect in each case.
# Repeat the tests using <code>asl</code> instructions instead of <code>lsr</code> instructions. Describe and explain the effect in each case.
# Revert to the original code.
# The original code includes one <code>iny</code> instruction. Test with one to five consecutive <code>iny</code> instructions. Describe and explain the effect in each case. '''Note:''' it is helpful to place the Speed slider is on its lowest setting (left) for these experiments.
# Revert to the original code.
# Make each pixel a random colour. (Hint: use the psudo-random number generator mentioned on the [[6502 Emulator]] page).
=== Challenges (Optional, Recommended) ===
# Set all of the display pixels to the same colour, except for the middle four pixels, which will be drawn in another colour.
# Write a program which draws lines at the top and bottom of the display:
#* A red line across the top
#* A green line across the bottom
== Write-Up ==
Post an entry on your blog describing your experiments in this lab. Follow the [[Blog Guidelines]]. Include code as text (and not screenshots), but feel free to include screenshots of the bitmapped display.
Include in your blog post:
# An introduction, so that someone who happens across your blog will understand the context of what you're writing about.
# The results from the ''Calculating Performance'' and ''Modifying Code'' portions of the lab, including the code, a description of how the code works, and the results produced.
# The results of the Optional sections, if you performed them, and your explaination for each observed result.
# Your experiences with this lab -- your impressions of Assembly Language, what you learned, and your reflections on the process.
Remember to follow the [[Blog Guidelines]] as you write.