Вы находитесь на странице: 1из 7

ECE 3120

Lab 6 – BRANCHES and LOOPS


 
The purpose of this lab is to introduce you to basic programming on the 68HCS12 using program
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 and shown to the lab instructor at the
start of the lab session, and submitted with the final report.

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 by hand in hex.

Approved: Lab TA _____________________ Date ____________

PROGRAMMING ASSIGNMENT:

Write a fully-commented program for the Dragon12 board, called Lab6_loop.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 data should be stored starting
at address $1000 and the program should start execution at address $2000. The program should
do the following:

1- An array, called Data, can hold up to 254 signed data bytes. This means that the program
should be able to handle any size array in this range with any set of legal values by
changing ONLY the directives that create the array values and array size, without
modifying any instructions. The last element of the array is the ASCII of letter ‘e’ (a
delimiter). The program should stop when an element value is ‘e’. The number of loop
iteration varies depending on the length of the array defined in by the directive. Do not do
the computation on the delimiter. This is not a number in the array. Each byte can thus
have a value between -128 and +127. 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, ‘e’. Calculate the
expected results by hand in hex.
2- In this requirement and the next ones, choose appropriate data sizes for all the variables
and results. Calculate the sum of all the numbers in the array. Store the result in a
memory variable called total_sum. To reduce the chance of overflow, store the running
(and final) summation in a word.

Page 1 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 
3- Calculate the sum of all the negative numbers in the array. Store the result in a memory
variable called negative_sum.
4- Calculate the sum of all the positive numbers in the array. Store the result in a memory
variable called positive_sum.
5- Calculate the average of the array. Store the result in a memory variable called average.
6- Count the number of zeros in the array. Store the result in a memory variable called
zeros_cnt.
7- Count the number of positive numbers in the array. Store the result in a memory variable
called positive_cnt.
8- Count the number of negative numbers in the array. Store the result in a memory variable
called negative_cnt.
9- Count the number of odd numbers in the array. Store the result in a memory variable
called odd_cnt.
10- Count the number of even numbers in the array. Store the result in a memory variable
called even_cnt.
11- Count the number of array elements that are exact multiples of 10. Store the result in a
memory variable called div_10_cnt.
12- Store the maximum (most positive) and minimum (most negative) numbers in memory
variable called Max and Min, respectively. Also store their memory locations in
Max_address and Min_address, respectively.

Insert your code into the following program outline.


;-----------------------------------------------------------
;Lab#6
; Program Loops
;Your name and lab date
;Describe program function and purpose, using multiple lines
if necessary.
;-----------------------------------------------------------
absentry entry ;application entry point
include 'mc9s12dg256.inc'

org $1000 ;Data starts here

org 2000 ;Program code starts here


entry:
... ; Write your instructions here,
... ; according to the directions.
...
...
here: bra here ;Stay here forever to end program
;------------------- End Program Lab#5---------------------

Page 2 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 
2- In lab:
1. Enter the code, assemble it, and download it into the Dragon12 board using Code
Warrior. Create a listing file, named Lab6_loop.lst.
2. Use the single step, run to cursor, or breakpoint procedures to debug the first iteration.
You can use full speed after the first iteration.
3. For the first iteration, Observe and verify the correct register and memory results
carefully after each instruction. Record all values in the registers and memory contents
(all expressed in hex) in Table 1. Indicate which branches have taken and which ones
have not been taken.
4. In Table 2, record the results of the first iteration and the final values.

Table 1: Results of the first iteration

PC A B D X Y C V

Page 3 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 
PC A B D X Y C V

Page 4 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 
Table 2

Variable First iteration Final value


total_sum
negative_sum
positive_sum
average
zeros_cnt
positive_cnt
negative_cnt
odd_cnt
even_cnt
div_10_cnt
Max
Min
Max_address
Min_address 

Approved: Lab TA _____________________ Date ____________

3- Post lab:

Things to turn in as your Lab Report, attached in this order:

1. [25 marks] This assignment sheet, with your name at the top, signed by the TA where
shown. Your uncorrected pre-lab document (commented source code and expected
results).

2. [20 marks] A printout of the final *.asm and *.lst files.

3. Answers to the following questions:

1) [10 marks] Justify your choice of data size for each variable in memory (bytes,
words, or double words).

Page 5 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 
2) [10 marks] Justify if one of the results is not correct.
3) [25 marks] For the first iteration, explain why branches have (or have not) been
taken.
4) [10 marks] What are the advantages and disadvantages of having a delimiter
(special code) to indicate the end of an array, instead of using a predefined constant
for the array size?

Page 6 of 6 
 
ECE 3120
Lab 6 – BRANCHES and LOOPS
 

Think about it should we make a new lab for a word array??????????????

• Be able to process any array of 1 to 255 signed data words as follows. Each data word can have
a value between -32768 and +32767. 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 directive that creates the
array values, without modifying any instructions or other directives.

Page 7 of 6 
 

Вам также может понравиться