$30
OBJECTIVES
• Become introduced to AVR assembly programming and the ATxmega128A1U microcontroller.
• Further understand how to utilize Atmel Studio for creating, simulating, and emulating a program.
• Design an assembly program to filter and store data based on certain criteria.
INTRODUCTION
The foundation of every computer architecture is a specific set of operations. In general, each operation within a computer architecture can be referenced by a unique numeric value known as an operation code (opcode)[1], and the set of all operation codes for an architecture defines a low-level programming language often referred to as machine code. Additionally, an operation code is also generally given a symbolic name, classifying it as an instruction. The collection of all instructions for a given architecture then defines the most abstract level of the architecture, often referred to as the Instruction Set Architecture (ISA), or more frequently, the assembly language.
With an assembly language, a computer program[2] can be written much more quickly than with a machine code. However, for a given computer architecture to be able execute a program written in an assembly language, the program must first be converted into an appropriate machine code format with a pre-built software program often referred to as an assembler[3], and then stored into some appropriate computer memory.
LAB STRUCTURE
In this lab, you will start to gain familiarity with the ATxmega128A1U microcontroller (generally referred to in this course as the XMEGA) as well further understand how to leverage Atmel Studio. First, you will learn various fundamental information regarding the ATxmega128A1U, the AVR assembler, and Atmel Studio. Then, you will begin to utilize the AVR ISA to design your first AVR assembly language program. After creating this program, your microcontroller will be able to filter and store data based on several given conditions.
REQUIRED MATERIALS SUPPLEMENTAL MATERIALS
• Atmel XMEGA AU Manual (doc8331) • Assembly Language Conversion: GCPU to AVR
• Atmel ATxmega128A1U Manual (doc8385) • Atmel Studio User Guide
• AVR Instruction Set (doc0856) • Utilizing Watch in Atmel Studio
• AVR Assembler Directives • Assembly Auto Complete Extension User Guide
• AVR Assembler User Guide • lab1_u20_skeleton.asm
• OOTB µPAD v2.0 with USB A/B cable
• Digilent Analog Discovery (DAD) with Waveforms software
PRE-LAB PROCEDURE
REMINDER OF LAB POLICY
You must re-read the Lab Rules & Policies before submitting any pre-lab assignment and before attending any lab.
Throughout this course, it will be necessary to conduct individual research. When doing so, various types of documentation, e.g., manuals, datasheets, application notes, and tutorials, will all be of interest.
Below, you will begin to become exposed to some important documentation relevant to this course, and will learn some basics regarding the ATxmega128A1U microcontroller, the AVR assembler, and Atmel Studio.
1. Study §§ 1-4 of the Atmel XMEGA AU Manual (doc8331), a more general user manual describing the XMEGA AU computer architecture. Additionally, study §§ 3, 6, and 7 of the Atmel ATxmega128A1U Manual (doc8385), the specific datasheet for the ATxmega128A1U microcontroller. Then, skim through the AVR Instruction Set (doc0856) to get an idea of the operations available to AVR microcontrollers. Next, read both the following webpage and user guide regarding the AVR assembler. Finally, look through the following section within the Atmel Studio User Guide regarding debugging.
PRE-LAB EXERCISES
i. Go through your parts list (available at here). Identify any missing parts and report this to your PI and in your lab report. If all parts are there, indicate this in your lab report.
ii. Which type of memory alignment is used for program memory in the ATxmega128A1U? Byte-alignment, or word-alignment? What about for data memory?
iii. In which section of program memory is address 0xF0D0 located?
iv. Which assembler directive places a byte of data in program memory? Which assembler directive allocates space within data memory? Which assembler directives allow you to provide expressions (either constant or variable) with a meaningful name?
v. Which assembly instructions can be used to read from (flash) program memory? For each instruction, list which registers can be used as an operand.
vi. Which assembly instructions can be used to load data indirectly from data memory within XMEGA AU microcontrollers? Which assembly instructions can be used to store data indirectly to data memory?
vii. Which assembly instruction can be used to load data directly from the I/O memory of XMEGA AU microcontrollers? Which assembly instruction can be used to store data directly to the I/O memory?
viii. If you were to use the Memory debug window of Atmel Studio to verify that some datum was correctly stored at address 0xBADD within program memory of the ATxmega128A1U, which address would you specify within the debug window?
ix. When using the internal SRAM (not EEPROM), which memory locations can be utilized for the data segment (.dseg)? Why?
x. Which is the first (i.e., lowest) program memory address that would require the relevant RAMP register to be changed from its initial value of zero? Why?
xi. In the context of pointing an index to a specific program memory address within an XMEGA AU architecture, explain why and how the address value should first be altered. Similarly, in the context of pointing an index to a specific data memory address, explain why the address value should not be altered.
Now, you will design your first AVR assembly language program, lab1.asm. A skeleton for this file is provided on our course website and is also available through the Supplemental Materials section of this document.
Overall, this program should filter data stored within a predefined input table based on a set of given conditions and store a subset of filtered values into an output table. More specifically, the following bulleted list describes an algorithm that should be performed on each item within the predefined input table, until an end-of-table (EOT) value of NULL, defined to be zero, is encountered within the table. Note that the algorithm should be executed in the same order as the bulleted list is provided, and for each iteration of the algorithm, only one of the three overall conditions within the bulleted list should be performed.
Ø If bit 6 of the 8-bit value is set, divide the value by 2. Then, if the resulting value is greater than 55, subtract 8 and store it to the first available location within the output table; otherwise, do not store anything to the output table.
Ø Else, if bit 6 is not set, multiply the value by 2. Then, if the resulting value of the data is less than or equal to 114, add 191 and store this result to the first available location within the output table.
The following are additional specifications for the program:
v The input table should be placed in program memory, starting at address 0xABCD, and should consist of the 8-bit data provided in the left-hand of Table 1 (given on the following page), where each value in this column should be stored sequentially in memory, without any padding, in the same format provided. (Data is given in decimal, hexadecimal, binary, octal, and ASCII formats to demonstrate that Atmel Studio can interpret values in each of these given formats.)
v An output table should be allocated within data memory, starting at address 0x3700.
v All values should be interpreted as unsigned, i.e., instructions that interpret data as a signed value (e.g., BRLT, BRGE, etc.) should not be utilized.
v Upon finding the EOT value within the input table, the output table should be terminated with a NULL character.
Table 1: Memory Table
Data
Data (ASCII)1
99
c
0x3B
;
0164
t
0b00111111
?
0x44
D
0x55
U
‘p’
p
0112
J
‘t’
t
0b00111010
:
‘<’
<
0x39
9
0x57
W
49
1
100
d
0
NULL
1ASCII format supported by Atmel Studio
If the program is written as specified above, the resulting output table should contain the message “2021!” (an exclamation for a better year) when the relevant data is viewed in terms of the ASCII encoding format supported by Atmel Studio. To view the data in this format, a Memory debug window within Atmel Studio should be utilized.
NOTES:
v The second column of Table 1 provides the relevant input table data in terms of the ASCII encoding format supported by Atmel Studio, simply to allow ease of verification if debugging with a Memory view window in Atmel Studio. (In general, ASCII provides a standard set of encoded values, often in terms of seven bits although sometimes in terms of eight bits if additional symbols are supported, for
commonly used symbols in human language. An example ASCII table can be found at www.asciitable.com.)
v In order to make your code modular and portable (i.e., able to be reused in different contexts), utilize assembler directives. For example, use assembler directives to create constant or variable identifiers for pertinent memory addresses within your input/output tables, for EOT values, etc.
v A Watch window, available under Debug | Windows | Watch within Atmel Studio, is used to view memory locations while debugging a program; to learn more about Watch windows, navigate to Debugging | Memory View within the Atmel Studio User Guide, as well as to the Using Watch in Atmel Studio document located on the course website, listed under Software/Docs.
v To facilitate programming in the AVR assembly language within Atmel Studio, it is recommended that you install the Auto Complete Extension created by a former 3744 student. To learn how to do so, refer to the Supplemental Materials section of this document.
1. Make a flowchart or write pseudocode for the above program. (This is required for ALL lab programs and may not be specifically requested in future lab documents.)
2. Create the relevant assembly language program, lab1.asm, as specified above. A skeleton for this file is provided on our course website and is also available through the Supplemental Materials section of this document.
3. Test your program using the Atmel Studio software simulator. Utilize debugging tools to verify that the program works as specified.
4. Emulate the program on your µPAD to verify that the program also works on your hardware. Utilize the same debugging tools.
5. Take a screenshot of a Memory view window after executing the relevant program, showing the entire output table at the appropriate memory locations.
PRE-LAB PROCEDURE SUMMARY
1) Read the specified sections within the relevant documentation. 2) Answer all pre-lab exercises.
3) Make a flowchart or write pseudocode for the described program.
4) Write the relevant assembly program, lab1.asm. Verify its correctness.
5) Capture a screenshot of a Memory view window displaying the resulting output table after executing the program.
[1] Operation codes are often represented in terms of fields of zeroes and ones, otherwise referred to as bit fields, where these fields represent a unique, encoded binary number. For hardware to handle bit fields, some form of encoding/decoding circuitry must be utilized.
[2] A program, or program of execution, is a collection of either computer instructions or operation codes that direct which operations a computer is to perform.
[3] Normally, assemblers are paired with an additional software program, generally known as a preprocessor, to recognize additional keywords, known as assembler directives, which specify actions to be performed directly by the assembler (and not by the computer for which the code is assembled).