EE 308 - LAB 4

Assembly Language Programming

Introduction and Objectives

The purpose of this lab is to write a few assembly language programs and test them on the simulator and on your EVBU.

Pre-Lab
Make sure you have the programs clearly thought out and written down before you come to lab. You should put all your code starting at memory location 0x0800. You are encouraged to bring the programs in on disk.

The Lab

As in last week's lab you will write some programs in assembly language and run the programs on the HC12 simulator and the EVBU. To make sure your programs work you will use D-Bug 12 op codes as your input data. There is one problem when running programs on the simulator - D-Bug 12 code which is present in the EVBU is not on the simulator. We can fix this problem by loading D-Bug 12 into the simulator. The following tells you how to do that.

Write and run the following programs:

1.
Write a program which writes an 0xff to address 0x0002, and then increments address 0x0000 indefinitely. (Note: this is a four-line program.)

Test your program both on the simulator and the EVBU. Trace through the program on the simulator and observe what happens to the data at address 0x0000. Check that the port PA lines are being toggled on your EVBU. (Use a logic probe to verify that the Port B lines are toggling.)

2.
Write a program to swap the last element of an array with the first element, the next-to-last element with the second element, etc. The array should have 0x20 eight-bit numbers and should start at 0x0900. (This is a problem from the homework due Feb. 4.)

Check that your program works both on the simulator and the EVBU. Use the following data for your test:

  0 1 2 3 4 5 6 7 8 9 A B C D E F
090 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
091 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F

3.
Write a program to compute the sum of the positive numbers of an array with 0x30 signed eight-bit numbers. Store the sum at 0x0900-0x0901. The array starts at 0xe000. (This is a problem from the homework due Feb. 11.)

Test your program on the simulator and the EVBU. What is the value of the sum stores at 0x0900?

4.
Write a program that puts the smallest one-byte signed number from memory locations 0xFCE0 through 0xFCFF in accumulator A and memory location 0x0900. (Note: The smallest possible one-byte signed number is 0x80 = -12810.) Test your program on the simulator and EVBU.

5.
Write a program that puts the lowest unsigned number from memory locations 0xFCE0 through 0xFCFF in accumulator A and memory location 0x0900. (Note: The lowest possible one-byte unsigned number is 0x00 = 010). Test your program on the EVBU. Note that this program will be the same as for Part 4 with one instruction changed.

Loading Programs into EEPROM

You can load programs into the on-chip EEPROM. When loaded in EEPROM your program will remain on your HC12 even after turning off power. Before loading your program into EEPROM, you must re-assemble it after modifying your program to start your code at address 0x0D00.

The details of how to download your program into EEPROM are given in the Universal Evaluation Board User's Manual in Appendix E, and are summarized here, with a description of how to make this work with our computers.

After the code is in the EEPROM, you can run it in one of two ways - 1) From D-Bug 12, set the program counter to 0x0D00 and `g` (or `g 0D00`); or 2) Move jumper W3 to its other position (position 1), and reset or power-cycle the EVBU. (Note that if you run your program using method 2, you cannot easily re-enter D-Bug 12 to check the results of your program. We will use method 2 in later labs where we won't need to re-enter D-Bug 12 after starting a program.)

1.
Load your last program (which finds the lowest unsigned number) into EEPROM. Run it by giving the G 0D00 command from D-Bug 12. Verify that the performance is the same as when you ran it from RAM.

2.
Turn off power to your EVBU. Turn power back on, and rerun your program by giving the G 0D00 command from D-Bug 12. Verify that your program stayed in EEPROM.



Bill Rison, <rison@ee.nmt.edu >
Tue Feb 2 1999

© 1999, New Mexico Tech