Difference between revisions of "6502 Assembly Language Lab (Old Version)"

From CDOT Wiki
Jump to: navigation, search
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[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.}}
+
{{Admon/important|This lab is not used in the current semester.|Please refer to the other labs in the [[:Category:SPO600 Labs|SPO600 Labs]] category.}}
 +
[[Category:SPO600 Labs - Retired]]{{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.}}
  
 
== Resources ==
 
== Resources ==
* [[6502]]
+
* [[6502]] Wiki Page
 
* [[6502 Emulator]]
 
* [[6502 Emulator]]
 
* [[6502 Emulator Example Code]]
 
* [[6502 Emulator Example Code]]
Line 12: Line 13:
  
 
=== Setup ===
 
=== Setup ===
1. Organize a group of 4-6 students around one of the monitor/whiteboard groups in the classroom. Arrange the furniture so that everyone has a comfortable view of the display.
+
1. Enter the breakout room assigned to you.
 +
2. Select one person to be the "Driver", who will type/operate the computer for the group.
 +
3. The driver will open the [[6502 Emulator]] at [http://6502.cdot.systems] (and, ideally, this lab page as well).
  
2. Gather these supplies:
+
{{Admon/tip|Sharing Results|Decide how group results will be shared between the members of the group. (Suggestion: consider using a git repository).}}
* HDMI cable
 
* Whiteboard markers
 
 
 
3. Select one person to be the "Driver", who will type/operate the computer for the group. That person should connect a device (laptop, table) to the HDMI display and open the [[6502 Emulator]] at [http://6502.cdot.systems] as well as this Lab page. It's a good idea to ensure that the Speed slider on the emulator is at its lowest setting (left) and that the Text Screen is turned off (unchecked).
 
 
 
4. Decide how group results will be shared between the members of the group. (Suggestion: consider using a git repository).
 
  
 
{{Admon/important|Save Your Work|The emulator '''does not''' save your work. Remember to periodically save it to a file (copy-and-paste the code).}}
 
{{Admon/important|Save Your Work|The emulator '''does not''' save your work. Remember to periodically save it to a file (copy-and-paste the code).}}
  
 
=== Bitmap Code ===
 
=== Bitmap Code ===
4. Paste this code into the emulator:
+
3. Paste this code into the emulator:
 
   
 
   
 
  lda #$00 ; set a pointer at $40 to point to $0200
 
  lda #$00 ; set a pointer at $40 to point to $0200
Line 32: Line 29:
 
  sta $41
 
  sta $41
 
   
 
   
  lda #$07 ; colour
+
  lda #$07 ; colour number
 
   
 
   
 
  ldy #$00 ; set index to 0
 
  ldy #$00 ; set index to 0
 
   
 
   
  loop: sta ($40),y ; set pixel
+
  loop: sta ($40),y ; set pixel at the address (pointer)+Y
 
   
 
   
 
  iny ; increment index
 
  iny ; increment index
Line 42: Line 39:
 
   
 
   
 
  inc $41 ; increment the page
 
  inc $41 ; increment the page
  ldx $41 ; get the page
+
  ldx $41 ; get the current page number
 
  cpx #$06 ; compare with 6
 
  cpx #$06 ; compare with 6
 
  bne loop ; continue until done all pages
 
  bne loop ; continue until done all pages
 
   
 
   
  
5. 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 everyone in your group understands how it works.
+
4. 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 everyone in your group understands how it works. Try some experiments: use different colours, or draw only every second dot.
 
 
6.  Add this instruction after the <code>loop:</code> label and before the <code>sta ($40),y</code> instruction:
 
  tya
 
 
 
7. What visual effect does this cause, and how many colours are on the screen? Why?
 
 
 
8. Add this instruction after the <code>tya</code>:
 
  lsr
 
 
 
9. What visual effect does this cause, and how many colours are on the screen? Why?
 
  
10. 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.
+
=== Writing Code ===
 +
5. Write code to draw a green line across the top of the bitmap screen and a blue line across the bottom.
  
11. Repeat the tests using <code>asl</code> instructions instead of <code>lsr</code> instructions. Describe and explain the effect in each case.
+
6. Extend the previous code to draw a yellow line down the left side of the screen and a purple line down the right side.
  
12. Remove the <code>tya</code> and all <code>asl</code> and <code>lsr</code> instructions.
+
=== Performance ===
  
13. 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:''' ensure that the Speed slider is on its lowest setting (left) for these experiments.
+
7. In the [[#Resources|Resources]] section, the opcode/instruction references will tell you the number of machine cycles that each instruction will take. If your system is running at 1 MHz (a typical speed for a 6502 processor), each machine cycle will take 1 microsecond (uS). What is the total time that your code (from step 6) will take to execute?
  
=== Writing Code, Part 1 ===
+
=== Optional (Recommended): Experiments ===
14. Write code to draw a green line across the top of the bitmap screen and a blue line across the bottom.
 
  
=== Writing Code, Part 2 ===
+
Go back to the bitmap code above, and try these experiments:
15. Extend the previous code to draw a yellow line down the left side of the screen and a purple line down the right side.
+
# 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.
 +
# Remove the <code>tya</code> and all <code>asl</code> and <code>lsr</code> instructions.
 +
# 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:''' ensure that the Speed slider is on its lowest setting (left) for these experiments.
  
 
== Write-Up ==
 
== Write-Up ==
 
Post an entry on your blog describing your experiments in this lab. Include:
 
Post an entry on your blog describing your experiments in this lab. Include:
 
# An introduction, so that someone who happens across your blog will understand the context of what you're writing about.
 
# An introduction, so that someone who happens across your blog will understand the context of what you're writing about.
# The results from the ''Bitmap Code'' portion of the lab, describing what happened in each case and the reasons for it.
+
# The results from the ''Writing Code'' portions of the lab, including the code, a description of how the code works, and the results produced.
# The results from the two ''Writing Code'' portions of the lab, including the code, a description of how the code works, and the results produced.
+
# Your answers to the ''Performance'' question, including a description of how you reached your answer.
# Your experiences with this lab -- your impressions of the Assembly Language, what you learned, and your reflections of the process.
+
# Optional (Recommended): the results of the Experiments section (above), and your explaination for each observed result.
 +
# Your experiences with this lab -- your impressions of the Assembly Language, what you learned, and your reflections on the process.
  
 
Remember to follow the [[Blog Guidelines]] as you write.
 
Remember to follow the [[Blog Guidelines]] as you write.

Latest revision as of 10:23, 15 September 2022

Important.png
This lab is not used in the current semester.
Please refer to the other labs in the SPO600 Labs category.
Lab icon.png
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.

Resources

Lab 1

Setup

1. Enter the breakout room assigned to you. 2. Select one person to be the "Driver", who will type/operate the computer for the group. 3. The driver will open the 6502 Emulator at [1] (and, ideally, this lab page as well).

Idea.png
Sharing Results
Decide how group results will be shared between the members of the group. (Suggestion: consider using a git repository).
Important.png
Save Your Work
The emulator does not save your work. Remember to periodically save it to a file (copy-and-paste the code).

Bitmap Code

3. 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

4. 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 everyone in your group understands how it works. Try some experiments: use different colours, or draw only every second dot.

Writing Code

5. Write code to draw a green line across the top of the bitmap screen and a blue line across the bottom.

6. Extend the previous code to draw a yellow line down the left side of the screen and a purple line down the right side.

Performance

7. In the Resources section, the opcode/instruction references will tell you the number of machine cycles that each instruction will take. If your system is running at 1 MHz (a typical speed for a 6502 processor), each machine cycle will take 1 microsecond (uS). What is the total time that your code (from step 6) will take to execute?

Optional (Recommended): Experiments

Go back to the bitmap code above, and try these experiments:

  1. Add this instruction after the loop: label and before the sta ($40),y instruction: tya
  2. What visual effect does this cause, and how many colours are on the screen? Why?
  3. Add this instruction after the tya: lsa
  4. What visual effect does this cause, and how many colours are on the screen? Why?
  5. Repeat the above tests with two, three, four, and five lsr instructions in a row. Describe and explain the effect in each case.
  6. Repeat the tests using asl instructions instead of lsr instructions. Describe and explain the effect in each case.
  7. Remove the tya and all asl and lsr instructions.
  8. The original code includes one iny instruction. Test with one to five consecutive iny instructions. Describe and explain the effect in each case. Note: ensure that the Speed slider is on its lowest setting (left) for these experiments.

Write-Up

Post an entry on your blog describing your experiments in this lab. Include:

  1. An introduction, so that someone who happens across your blog will understand the context of what you're writing about.
  2. The results from the Writing Code portions of the lab, including the code, a description of how the code works, and the results produced.
  3. Your answers to the Performance question, including a description of how you reached your answer.
  4. Optional (Recommended): the results of the Experiments section (above), and your explaination for each observed result.
  5. Your experiences with this lab -- your impressions of the Assembly Language, what you learned, and your reflections on the process.

Remember to follow the Blog Guidelines as you write.