Difference between revisions of "6502 Assembly Language String Lab"
Chris Tyler (talk | contribs) (Created page with "Category:SPO600 Labs{{Admon/lab|Purpose of this Lab|In this lab, you will write code with string handling and character conversions in 6502 assembly language, in prepa...") |
Chris Tyler (talk | contribs) |
||
(11 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 write code with string handling and character conversions in [[6502]] assembly language, in preparation for learning more complex x86_64 and AArch64 assembly language.}} | + | [[Category:SPO600 Labs - Retired]] |
+ | {{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.}} | ||
+ | {{Admon/lab|Purpose of this Lab|In this lab, you will write code with string handling and character conversions in [[6502]] assembly language, in preparation for learning more complex x86_64 and AArch64 assembly language.}} | ||
== Resources == | == Resources == | ||
Line 7: | Line 9: | ||
** [[6502_Emulator#ROM_Routines|ROM Routines]] for character output | ** [[6502_Emulator#ROM_Routines|ROM Routines]] for character output | ||
* [[6502 Emulator Example Code]] - Specifically: | * [[6502 Emulator Example Code]] - Specifically: | ||
− | ** [[6502_Emulator_Example_Code#Place_a_Message_on_the_Character_Display|Place a Message on the Character Display]] - for an example of defining | + | ** [[6502_Emulator_Example_Code#Place_a_Message_on_the_Character_Display|Place a Message on the Character Display]] - for an example of defining text using DCB, and writing that text to the screen with and without the ROM routines |
* Opcode/Instruction References | * Opcode/Instruction References | ||
** [http://www.6502.org/tutorials/6502opcodes.html 6502 Opcodes with Register Definitions] | ** [http://www.6502.org/tutorials/6502opcodes.html 6502 Opcodes with Register Definitions] | ||
Line 16: | Line 18: | ||
== Techniques == | == Techniques == | ||
* To convert a digit into a character, add the value of the ASCII character "0" ($30, 41). For example, $05 + $30 = $35, which is the ASCII code for the digit "5". | * To convert a digit into a character, add the value of the ASCII character "0" ($30, 41). For example, $05 + $30 = $35, which is the ASCII code for the digit "5". | ||
− | * Decimal (BCD) mode may be useful for some of these problems. | + | * Decimal ([[BCD]]) mode may be useful for some of these problems. |
** To get the upper digit from a BCD byte, perform LSR four times to shift the upper four bits to the lower four bit locations and zero the upper four bits. | ** To get the upper digit from a BCD byte, perform LSR four times to shift the upper four bits to the lower four bit locations and zero the upper four bits. | ||
** To get the lower difit from a BCD byte, AND the byte with $0f. | ** To get the lower difit from a BCD byte, AND the byte with $0f. | ||
− | ** Remember to turn decimal mode on for operations on BCD bytes, and turn it off for other operations. | + | ** Remember to turn decimal mode on for operations on BCD bytes, and turn it off for other operations so that it does not affect binary math (use the SED and CLD instructions). |
− | ** Decimal mode | + | ** Decimal mode only affects add and subtract operations (ADC and SBC). |
* To indicate the cursor position, you may want to use reverse video, which is available in the [[6502 Emulator|emulator]] by ORing a printable ASCII code with $80 to turn on the high bit. | * To indicate the cursor position, you may want to use reverse video, which is available in the [[6502 Emulator|emulator]] by ORing a printable ASCII code with $80 to turn on the high bit. | ||
+ | * It is recommended that you run the emulator at its highest speed (move the Speed slider to the right). | ||
== Lab 4 == | == Lab 4 == | ||
Line 38: | Line 41: | ||
=== Pick Two Options === | === Pick Two Options === | ||
− | Pick and implement two of the following options for this lab. Use the emulator's [[6502_Emulator#ROM_Routines|ROM routines]] for at least one (and possibly both) problems. In each case, make the software easy to use, with appropriate user prompts and feedback, and ensure that | + | Pick and implement two of the following options for this lab. Requirements: |
+ | * Use the emulator's [[6502_Emulator#ROM_Routines|ROM routines]] for at least one (and possibly both) problems. | ||
+ | * In each case, make the software easy to use, with appropriate user prompts and feedback, and ensure that it looks good on the screen. | ||
==== Option 1: Adding Calculator ==== | ==== Option 1: Adding Calculator ==== | ||
# Create a subroutine which enables the user to enter two numbers of up to two digits. Indicate where the cursor is, and allow the user to use the digit keys (0-9), backspace, and enter keys. Return the user's input value in the accumulator (A) register. | # Create a subroutine which enables the user to enter two numbers of up to two digits. Indicate where the cursor is, and allow the user to use the digit keys (0-9), backspace, and enter keys. Return the user's input value in the accumulator (A) register. | ||
# Using this subroutine, write a program which add the two numbers (each of which is in the range 0-99) and print the result. | # Using this subroutine, write a program which add the two numbers (each of which is in the range 0-99) and print the result. | ||
+ | * Optional challenge: extend to more than 2 digits and add a running total capability with a clear key. | ||
==== Option 2: Data Input Form ==== | ==== Option 2: Data Input Form ==== | ||
− | # Create a subroutine which enables the user to enter a string of up to 40 characters. Decide how the data will be returned from the subroutine. The user should be able to use the left/right cursor keys backspace to edit the text | + | # Create a subroutine which enables the user to enter a string of up to 40 characters. Decide how the data will be returned from the subroutine. The user should be able to use the left/right cursor keys and backspace to edit the text, and the cursor location should be visible to the user. |
# Write a program which uses this subroutine to collect the user's name, address, city, province, and postal code, and then display this information formatted as a shipping address (for example, as shown below). | # Write a program which uses this subroutine to collect the user's name, address, city, province, and postal code, and then display this information formatted as a shipping address (for example, as shown below). | ||
Line 53: | Line 59: | ||
1750 Finch Ave E | 1750 Finch Ave E | ||
Toronto ON M2J 2X5 | Toronto ON M2J 2X5 | ||
+ | |||
+ | * Optional challenge: validate the province/territory and the postal code format. | ||
==== Option 3: Hexdump ==== | ==== Option 3: Hexdump ==== | ||
− | # Create a subroutine which enables the user to enter a 4-digit hexadecimal value. Allow the use of the backspace key for editing, and show the user the cursor location. | + | # Create a subroutine which enables the user to enter a 4-digit hexadecimal value. Allow the use of the backspace key for editing, and show the user the cursor location. Decide how the data will be returned by this subroutine. |
− | # Using this subroutine, ask the user for a starting address and length, and then output a hexdump of the specified memory locations, formatted to show address and data information in some layout. If the output is longer than the screen, pause for user input (e.g., "Press ENTER to continue" or something similar) every 20 lines. | + | # Using this subroutine, ask the user for a starting address and a length (in bytes), and then output a hexdump of the specified memory locations, formatted to show address and data information in some layout. If the output is longer than the screen, pause for user input (e.g., "Press ENTER to continue" or something similar) every 20 lines. |
− | + | * Optional challenge: add a display of ASCII data on the right-hand side, similar to the output of the linux command <code>od -A x -t xz -v ''filename''</code> | |
==== Option 4: Screen Colour Selector ==== | ==== Option 4: Screen Colour Selector ==== | ||
− | # Create a subroutine which displays on the character display a list of colours available on the bitmapped display, with one of the colours highlighted in reverse video (white on black). The user may use the up/down arrow keys change the highlighted row. Return the user's selection as a number in the accumulator (A) register. | + | # Create a subroutine which displays on the character display a list of colours available on the bitmapped display, one colour per line, with one of the colours names highlighted in reverse video (white on black). The user may use the up/down arrow keys to change the highlighted row. Return the user's selection as a number in the accumulator (A) register when they press Enter. |
− | # Using this subroutine, get a colour from the user, then fill the bitmap display with this colour. | + | # Using this subroutine, get a colour from the user, then fill the bitmap display with this colour, and allow the user to select a different colour. |
+ | * Optional challenge: update the colour on the bitmapped display as the user scrolls through the colour-selector list. | ||
=== Write-Up === | === Write-Up === | ||
Line 66: | Line 75: | ||
# 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 two ''Writing Code'' portions of the lab, including the code, a description of how the code works, and the results produced. Credit other sources appropriately (i.e., font/graphics data, code snippets) and ensure that you are in compliance with the licenses of any code snippets used. | # 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. Credit other sources appropriately (i.e., font/graphics data, code snippets) and ensure that you are in compliance with the licenses of any code snippets used. | ||
− | # Your experiences with this lab -- your impressions of the Assembly Language, what you learned, and your reflections | + | # 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 11:32, 28 January 2022
Contents
Resources
- 6502
- 6502 Emulator
- Peripherals (including the Character Screen)
- ROM Routines for character output
- 6502 Emulator Example Code - Specifically:
- Place a Message on the Character Display - for an example of defining text using DCB, and writing that text to the screen with and without the ROM routines
- Opcode/Instruction References
- Binary Coded Decimal (BCD) Mode
Techniques
- To convert a digit into a character, add the value of the ASCII character "0" ($30, 41). For example, $05 + $30 = $35, which is the ASCII code for the digit "5".
- Decimal (BCD) mode may be useful for some of these problems.
- To get the upper digit from a BCD byte, perform LSR four times to shift the upper four bits to the lower four bit locations and zero the upper four bits.
- To get the lower difit from a BCD byte, AND the byte with $0f.
- Remember to turn decimal mode on for operations on BCD bytes, and turn it off for other operations so that it does not affect binary math (use the SED and CLD instructions).
- Decimal mode only affects add and subtract operations (ADC and SBC).
- To indicate the cursor position, you may want to use reverse video, which is available in the emulator by ORing a printable ASCII code with $80 to turn on the high bit.
- It is recommended that you run the emulator at its highest speed (move the Speed slider to the right).
Lab 4
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.
2. Gather these supplies:
- 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 [1] 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).
Pick Two Options
Pick and implement two of the following options for this lab. Requirements:
- Use the emulator's ROM routines for at least one (and possibly both) problems.
- In each case, make the software easy to use, with appropriate user prompts and feedback, and ensure that it looks good on the screen.
Option 1: Adding Calculator
- Create a subroutine which enables the user to enter two numbers of up to two digits. Indicate where the cursor is, and allow the user to use the digit keys (0-9), backspace, and enter keys. Return the user's input value in the accumulator (A) register.
- Using this subroutine, write a program which add the two numbers (each of which is in the range 0-99) and print the result.
- Optional challenge: extend to more than 2 digits and add a running total capability with a clear key.
Option 2: Data Input Form
- Create a subroutine which enables the user to enter a string of up to 40 characters. Decide how the data will be returned from the subroutine. The user should be able to use the left/right cursor keys and backspace to edit the text, and the cursor location should be visible to the user.
- Write a program which uses this subroutine to collect the user's name, address, city, province, and postal code, and then display this information formatted as a shipping address (for example, as shown below).
Your order will be delivered to: J. Doe 1750 Finch Ave E Toronto ON M2J 2X5
- Optional challenge: validate the province/territory and the postal code format.
Option 3: Hexdump
- Create a subroutine which enables the user to enter a 4-digit hexadecimal value. Allow the use of the backspace key for editing, and show the user the cursor location. Decide how the data will be returned by this subroutine.
- Using this subroutine, ask the user for a starting address and a length (in bytes), and then output a hexdump of the specified memory locations, formatted to show address and data information in some layout. If the output is longer than the screen, pause for user input (e.g., "Press ENTER to continue" or something similar) every 20 lines.
- Optional challenge: add a display of ASCII data on the right-hand side, similar to the output of the linux command
od -A x -t xz -v filename
Option 4: Screen Colour Selector
- Create a subroutine which displays on the character display a list of colours available on the bitmapped display, one colour per line, with one of the colours names highlighted in reverse video (white on black). The user may use the up/down arrow keys to change the highlighted row. Return the user's selection as a number in the accumulator (A) register when they press Enter.
- Using this subroutine, get a colour from the user, then fill the bitmap display with this colour, and allow the user to select a different colour.
- Optional challenge: update the colour on the bitmapped display as the user scrolls through the colour-selector list.
Write-Up
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.
- 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. Credit other sources appropriately (i.e., font/graphics data, code snippets) and ensure that you are in compliance with the licenses of any code snippets used.
- 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.