Microsoft Word - 3130_Lab_5 The purpose of this lab is to introduce you to writing complete programs with the HCS12 using loops, branching, and arithmetic instructions. You will NEED to study the...

1 answer below »
referencing style N/A


Microsoft Word - 3130_Lab_5 The purpose of this lab is to introduce you to writing complete programs with the HCS12 using loops, branching, and arithmetic instructions. You will NEED to study the arithmetic and branching instructions in Huang chapter 2 before attempting this program. 1- Pre-lab: This must be completed before coming to the lab. 1 Prepare the first draft of the program described below. The program should contain directives and comments. Comments are a must 2 Calculate the expected results. PROGRAMMING ASSIGNMENT: Write a fully-commented program for the Dragon12 board, called Lab5.asm, including appropriate directives and labels for memory operands and constants. Use only one program loop. Comments should mostly describe WHAT you are accomplishing toward solving the problem, not HOW each instruction works alone. Every instruction may not have a comment, but small groups of instructions must have explanatory comments. The program should do the following: 1 An array, called Data, can hold up to 255 signed byte elements. Each element can store a number in the range 127 to -127. The last element in the array is -128 (a delimiter). The program should be able to handle any size of the array (up to 255 elements) with any set of legal values by changing ONLY the directives that create the array values without modifying any instruction. Do not do the computations on the delimiter. It is not a number in the array. Use directives to define the array and initialize it with 100, 127, - 127, 22, 0, -8, -1, 0, 1, 120, 77, -45, 0, -99, 2, -5, 110, 0, -1, 87, -128. You do not need to convert the array elements to hexadecimal. You can write them in decimal format and the assembler will convert them. Define any more variable as needed. 2 In this requirement and the next ones, choose appropriate data sizes for all the variables and results. Calculate the sum of all the elements of the array. Store the result in a Lab 5 – Braches and Loops ( Page 1 of 3 ) memory variable called total_sum. To reduce the chance of overflow, store the running (and final) summation in a word. You should extend each element to a signed word, and then add it to the running sum (total_sum). 3 Calculate the sum of all the negative numbers in the array. Store the result in a memory variable called negative_sum. To reduce the chance of overflow, store the running (and final) summation in a word. 4 Count the number of zeros in the array. Store the result in a memory variable called zeros_cnt. 5 Count the number of positive numbers in the array. Store the result in a memory variable called positive_cnt. 6 Count the number of negative numbers in the array. Store the result in a memory variable called negative_cnt. 7 Count the number of array elements that are even. Store the result in a memory variable called even_cnt. Hint: when dividing these numbers by 2, the remainder is zero. An easier way is, if bit 0 is zero, the number is even. 8 Store the minimum value in the array in a memory variable called Min. 9 Multiply each element by 10 and store the result in a word array. You should define this array as Array_10. You should use signed multiplication. 10 Store the average of the array elements in a memory variable called average. You need to count the number of elements of the array. 2- In lab: 1. Enter the code, assemble it, and download it into the Dragon12 board using Code Warrior. 2. Use the single step to debug the first iteration. This should help make sure that the program is working as expected. You can use full speed after the first iteration. 3. In the first iteration, observe and verify the values of the registers and memory variables after executing each instruction. Verify which branches have been taken and which ones have not been taken. 4. In Table 1, record the final results. Justify if these results are different from the expected ones. Table 1 Variable Expected value The value obtained from the program total_sum negative_sum zeros_cnt positive_cnt negative_cnt even_cnt Min Average 3 Post lab: Things to turn in as your Lab Report, attached in this order: 1. This assignment sheet, with your name at the top, signed by the TA where shown. 2. [30 marks] A printout of the final assembly program. 3. [10 marks] Table 1. Justify when the results are not correct. 4. [20 marks] For the first iteration, explain why branches have or have not been taken.
Answered 1 days AfterApr 07, 2021

Answer To: Microsoft Word - 3130_Lab_5 The purpose of this lab is to introduce you to writing complete programs...

Gaurav answered on Apr 08 2021
131 Votes
;*****************************************************************
;* This stationery serves as the framework for a *
;* use
r application (single file, absolute assembly application) *
;* For a more comprehensive program that *
;* demonstrates the more advanced functionality of this *
;* processor, please see the demonstration applications *
;* located in the examples subdirectory of the *
;* Freescale CodeWarrior for the HC12 Program directory *
;*****************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
        INCLUDE 'derivative.inc'
ROMStart EQU $4000 ; absolute address to place my code/constant data
; variable/data section
ORG RAMStart
; Insert here your data definition.
Data dc.b 100, 127, -127, 22, 0, -8, -1, 0, 1, 120, 77, -45, 0, -99, 2, -5, 110, 0, -1, 87, -128
total_sum ds 2
negative_sum ds 2
zeros_cnt ds 1
positive_cnt ds 1
negative_cnt ds 1
even_cnt ds 1
Min ds 1
average ds 1
count ds 1
tmp ds 2
Array_10 ds.w 255
; code section
ORG ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here