Program Loops in 68HCS12 Microcontroller using Assembly Language, Lab Reports of Microcomputers

A lab assignment for ece-3120 course in fall 2008, which introduces students to programming the 68hcs12 microcontroller using program loops and arithmetic instructions. The lab focuses on writing a program in assembly language to process an array of signed data bytes, calculate the sum of positive, negative numbers and zeros, and the total sum of all numbers in the array. The program should start execution at $1000 and store the results in specific memory locations.

Typology: Lab Reports

Pre 2010

Uploaded on 07/30/2009

koofers-user-apw
koofers-user-apw 🇺🇸

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ECE-3120
Fall 2008
LAB 3 –PROGRAM LOOPS
The purpose of this lab is to introduce you to basic programming the 68HCS12 using
program loops and arithmetic instructions. You will NEED to study about the arithmetic
and branching instructions in Huang chapter 2 before attempting this program.
PRE-LAB:
Prepare pseudocode and the first draft of the program and calculate the expected results
by hand. This must be completed before coming to the lab and shown to the lab instructor
at the start of the lab session.
Approved: Lab TA _____________________ Date ____________
PROGRAMMING ASSIGNMENT:
Write a fully-commented program for the HC12 board, including appropriate directives
and labels for memory operands and constants, called Loop.asm. It must use a single
program loop for most of the work. The program should do the following:
Be able to process any array containing 1 to 255 signed data bytes as follows.
Each byte can thus have a value between -128 and +127. This means that the
program should be able to handle any size array in this range, with any set of
values, by changing ONLY the directives that create the array values and
array size, without modifying any instructions.
Calculate the sum of all the positive numbers in the array.
Calculate the sum of all the negative numbers in the array.
Count the number of zeros in the array.
Calculate the total sum of all numbers in the array.
The code must start execution at $1000.
The program directives should initialize the following signed decimal data byte array
in the data space (starting at $1200):
98, 130, -127, -3, 4, -15, -1, 0, 1, 140, 57, -55, 0, -99, in this order.
9/22/08 Page 1 of 3 Lab 3
pf3

Partial preview of the text

Download Program Loops in 68HCS12 Microcontroller using Assembly Language and more Lab Reports Microcomputers in PDF only on Docsity!

ECE-

Fall 2008

L A B 3 – P R O G R A M L O O P S

The purpose of this lab is to introduce you to basic programming the 68HCS12 using program loops and arithmetic instructions. You will NEED to study about the arithmetic and branching instructions in Huang chapter 2 before attempting this program.

P R E - L A B :

Prepare pseudocode and the first draft of the program and calculate the expected results by hand. This must be completed before coming to the lab and shown to the lab instructor at the start of the lab session.

_Approved: Lab TA _____________________ Date _____________

P R O G R A M M I N G A S S I G N M E N T :

Write a fully-commented program for the HC12 board, including appropriate directives and labels for memory operands and constants, called Loop.asm. It must use a single program loop for most of the work. The program should do the following:

  • Be able to process any array containing 1 to 255 signed data bytes as follows. Each byte can thus have a value between -128 and +127. This means that the program should be able to handle any size array in this range, with any set of values, by changing ONLY the directives that create the array values and array size, without modifying any instructions.
  • Calculate the sum of all the positive numbers in the array.
  • Calculate the sum of all the negative numbers in the array.
  • Count the number of zeros in the array.
  • Calculate the total sum of all numbers in the array.
  • The code must start execution at $1000.

The program directives should initialize the following signed decimal data byte array in the data space (starting at $1200): 98, 130, -127, -3, 4, -15, -1, 0, 1, 140, 57, -55, 0, -99, in this order.

The program should store in memory:

  • The sum of positive numbers in memory location $1300:$
  • The sum of negative numbers in memory location $1302:$
  • The number of zeros in memory location $
  • The total sum in memory location $1306:$

Procedure : First, use D-Bug12 to fill memory locations $1000 through $3BFF with zeros. Then assemble, download, and debug/execute the program as follows. a. Single-step through the program until it completes the first loop iteration and is ready to branch back to the start of the loop. Verify that each change is correct. b. Then set a breakpoint to stop execution at the end of each loop and run through rest of the program to the end, pausing at each breakpoint to display the important results. Verify that each result is correct at the end of each loop and that all four final results are correct at the end of the program. Use the listing file to determine the breakpoint address. Remember that the instruction at the breakpoint address is NOT executed when the break occurs; it is only executed when you resume execution after the break. c. Then reset the processor (which removes the breakpoint), download the program again, run it at full speed until it stops, and verify that the four final values are still correct. d. When finished debugging and executing, copy the entire terminal window output and paste it into a Notepad or Word document for inclusion in the report. You should edit out mistakes and unnecessary repetitions before submission.

_Approved: Lab TA _____________________ Date _____________