Starting from:

$30

CSC230-Assignment 3 AVR Assembly Language Solved

Upon successful completion of this assignment, you should be able to write AVR assembly language programs that:

ü  Assemble and execute correctly on the 2560 boards

ü  Use Immediate, Register, Direct and Indexed address modes. 

ü  Use loop structures

ü  Use index addressing to simulate arrays in memory

ü  Use the masks & shift instructors to write bytes of data to LEDs attached to a port.  

 

 



Assignment 3 Part 1:  Formative   

Part 1:  The program described in this part must be written, documented and submitted.  Please follow up with any questions you may have with the teaching team during office hours, as early as possible during the following week.  (This formative submission is intended for form your skills, rather than create a grade.  The summative evaluation, which results in a grade, will be reserved for Part 2 below.)  

Pseudo-code is a programming-like language that assists in program design, but is simpler or not as well defined as a programming language.  Pseudo-code will be used throughout CSC 230 and will appear similar to statements in the C, Python or Java programming languages.  It will be used to both define algorithms and serve as documentation throughout assembly language code.  

Consider the following pseudo-code ‘program’:  

number1 = 103; number2 = 41; number3 = 15;

diff = number1; diff -= number2; diff -= number3;

 result = diff;

Essentially, this ‘program’ calculates the difference of 3 constant values, number1 – number2 – number3, stores the result in memory location called result.  In Assignment 2 Part 1, this pseudo-code will be: 

•        Translated into AVR assembly language,

•        Tested on the AVR studio simulator

First, recall that the AVR microcontroller uses the Harvard architecture:  



The program that will be run by the microcontroller must be uploaded into the code segment, which is a flash memory, then the program is run by the microcontroller that can use the data segment, which is a static random access memory (SRAM), to store both temporary values and result.  Observe that the code segment can be initialized, as it is when we upload the program, but the data segment cannot.  Thus, we must store the initial (hard coded) values used by the program in the code segment, along with the program.  

Below is a template or starting assembly language program outline to be used in

Assignment 3 Part 1.  (It is also provided on the course site as A3P1.asm. ) 

.include "m2560def.inc"

;

;

***********************************************************

; * Program information goes here.                        *

; *  Examples include:  Course name, assignment number,   *

; *     program name, program description, program input, *

; *     program output, programmer name, creation date,   * ; *     dates of program updates. *

; *********************************************************

 

; *************************

; * Code segment follows: *

; *************************

.cseg

 

;************************

; Your code starts here:

;

 

 

 

 

 

;

; Your code finishes here.

;*************************

 

               done:     jmp done

 

; *************************

; * Data segment follows: *

; *************************

.dseg

.org 0x200

Directions: (This will require the use of the AVR Instruction Set reference document.) 

Ø  Follow the procedure described in the labs to use AVR studio to create a project called A3P1.aps.  

Ø  Type or copy and paste the template above.  

Ø  Build and (if no errors) simulate the run (or debug) of the program.  It really should not do anything, as there are no statements in the code segment.  

Ø  Type or copy and paste the first three lines of the pseudo-code above into the code segment, placing a semi-colon (;) at the beginning of each line, making them comments.  

Ø  After each line use an AVR load instruction, where one operand is a register and the other uses immediate addressing, to create these instructions in assembly language.

Build and simulate program execution, checking for correctness. 

Ø  Build and (if no errors) simulate the run (or debug) of the program.  

Ø  Create a comment for the diff = number1; instruction, then code it in assembly language. 

Ø  Create a comment for each of the lines that calculate the difference and code in assembly language (using the SUB instruction), where both operands are registers.  

Ø  Build and (if no errors) simulate the run (or debug) of the program.  

Ø  (Set up the SRAM:)  Create a memory location for the result, which we will assume to be 1 byte long, in the Data Segment by typing result .db 1 on the very last line, immediately following the .dseg  and .org 0x200 assembler directives.  Observe that the SRAM memory address (in hexadecimal) 0x200 has been named result and 1 byte has been set aside for it. 

Ø  Build and (if no errors) simulate the run (or debug) of the program.  Observe the SRAM at location 0x200 in the simulator.  

Ø  (Back to the code segment:)  Create a comment for the result = difference; instruction.  Use the store instruction with direct addressing to specify the location of result.  

Ø  Build and (if no errors) simulate the run (or debug) of the program.  Observe the

SRAM at location 0x200 in the simulator.  

Ø  Adjust the top of code comments to appropriately describe the program.

Make sure your code is fully documented, as described above.  Observe that the AVR Studio created a file in your directory called A3P1.asm

More products