CSC 230 Assignment 3 Solved

30.00 $

Category:

Description

5/5 - (3 votes)

Part 1: Called a formative submission, contains introductory activities that assist in the development of the final solution. The formative submission is due 1 week earlier than the final due date of the assignment.  This submission is designed to ensure you start to work on the assignment early enough to seek assistance before the final due date. When your Part 1 is as complete as possible, submit it on Connex under the Assignments, Assignment 3 Part 1

link.  If you feel there were any learning issues with this part of the assignment, follow up with the teaching team, during office hours, as early as possible during the week.

  • Part 2: Called a summative submission, this is the final submission of the assignment.  This will be graded in the week that follows the due date.  When your program is complete and tested, including appropriate documentation, submit it on Connex under the Assignments, Assignment 3 Part 2 link.  

Learning Objectives

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

Assignment 3 Part 2:  Summative  (will be graded)

Part 2:  Follow the procedure described in the labs to use AVR studio to create a project called A3P2.aps.

  1. Use a loop to write decrementing hexadecimal numbers into consecutive memory locations in the data memory, starting at memory address 0x200. The starting number, which is between 0x0 (inclusive) and 0xFF (inclusive) should be placed into a register (R16).  That starting number needs to be stored in the first data memory location.  Then the number will be decremented by 1 and stored in the next consecutive memory location.  This process of decrementing and storing will continue until the number 0 is the final value stored.   After each number is stored in memory, output the binary equivalent of the number on the LEDs attached to Ports L and B, with the least significant bit on Port L: bit 7.  Here is the pseudocode:

number = /* choose a number in (0x00, 0xFF] */ ; count = 0; while (number > 0) {  dest[count++] = number;      * Output number on LEDs *      * delay 0.5 second *

number –;

Observe that your documentation *should* include the above pseudo code.

  1. The fifth line of the above pseudo code (* Output number on LEDs * ) is described as follows: after each number is placed in memory, display the number, in binary on the LEDs on the board that are attached to Ports L and B.

Recall from lab 4 that the number must be spread out on every other bit to output to the port.  For example, to output the number 0xB = 0b1011 on port L, each of those 4 bits must be followed by another bit, lets use 0, such that the binary number becomes 0b10001010.  Observe that the 4 underlined bits were the original bits.  The conversion from (for example) 0b1111 to 0b10101010 is accomplished using a ‘mask’ to separate out a single bit, shifting it to the proper location and then using an OR operation to combine the bits together.

  1. The sixth line of the above pseudo code ( * delay 0.5 second * ). Please place the following lines in your code where the delay should occur:

rjmp delay: after:  ;next instruction

 

Then place the following at the very end of your code segment (i.e., after done: jmp done. )

; The delay code, which is placed *after* the done: jmp done

delay: ldi r24, 0x2A  ; approx. 0.5 second delay
outer: ldi r23, 0xFF
middle:  ldi r22, 0xFF
inner:  dec r22
        brne inner
        dec r23
        brne middle
        dec r24
        brne outer
        rjmp after

 

(Academic Integrity altert:  Always give credit to an author who agrees to let you use their code. For example, consider adding “Credit: L. Jackson for the writing the following 9 lines:”)

Test your code on the simulator in the AVR studio, then upload it onto an Arduino 2560 board in the ECS 249 lab and test.

 

  • Assignment-3-g0cp1i.zip