EE 308 - LAB 2

ASSEMBLER, SIMULATOR, AND MONITOR

Introduction and Objectives

This laboratory introduces you to the following 68HC12 assembly language programming tools:

An assembler takes assembly language code in a form that a human can reasonably read with a little practice, translates it to machine codes which a microprocessor can understand. and stores them in a .s19 file which the 68HC12 microcontroller can understand. In this lab we will use the Cosmic Software CA6812 assembler, which is on the PCs in the Digital/Microcontrollers lab. This is copyrighted software which is licensed for use on our lab computers only. There is a demo version of this assembler (as well as the Cosmic C compiler) available. It should be adequate for most of the labs in this course. Information about how to obtain this demo assembler and compiler will be posted on the EE 308 web page. In your HC12 kit you received a copy of the P&E Microsystems IASM12 assembler. You may put this assembler on your own PC, and may put it in your directory on the EE computer system. Using this assembler you can do much of the assembly language programming at home. IASM12 is similar to the Cosmic assembler we will use in lab.

The Cosmic CA6812 assembler produces an output file with a .h12 extension which the ZAP simulator uses. It also produces an output file with a .s19 extension which can be loaded into and run on the 68HC12. The D-Bug 12 monitor, running from HC12 EPROM, loads S19 records into the HC12 and provides some tools for debugging loaded programs.

The ZAP simulator simulates the operation of the 68HC12 on a computer. This has two advantages: you can try a program without having a 68HC12, and you can easily see information (such as register contents, number of cycles to complete, etc.) which are difficult or impossible to observe on an actual microcontroller. Again, the full ZAP simulator is a licensed program which cannot be distributed, but we have a demo version of the simulator which will be adequate for most of the labs in this course.

The relationship between these various programs is illustrated in Figure 1.


  
\begin{figure}
\epsfig{file=lab02_fig1.eps,width=5in}\end{figure}
Figure 1: The relationship between CA6812, ZAP, and D-Bug 12.

Pre-Lab

You should read this entire lab before coming to lab, and answer all of the questions in the pre-lab section before coming to lab.

The D-Bug 12 commands of interest for this lab are: ASM, BF, BR, NOBR, G, HELP, LOAD, MD, ,MDW, MM, MMW, RM, RD, and T. Read the descriptions of these commands in Chapter 3 of the M68EVB912B32 Evaluation Board User's Manual.

Questions to answer before lab:

The assembly language commands of interest are: LDAA, STAA, TAB, ABA, and ASRA. Read the descriptions of these commands in the 68HC12 CPU12 Reference Manual. At this point you will not understand everything the reference manual says about these instructions, but you should understand enough to get you through this lab.

Figure 2 is a simple program for the HC12. We will use it to illustrate how to use the assembler, the simulator and D-Bug 12.

; 68HC12 demo program
; Bill Rison
; 1/22/99

; This is a program to divide and multiply a number by two, 
; and store the results in memory

         title   "LAB 2 Demo Program"

evbram:  equ     $0800        ;0x0800 is start of user ram on 68HC12
prog:    equ     evbram       ;start program at beginning of RAM
data:    equ     evbram+$0100 ;

CODE:    section .text    ;The stuff which follows is program code
         org     prog     ;set program counter to 0x0800
         ldaa    input    ;Get input data into ACC A
         asra             ;Divide by 2
         staa    result   ;Save the result
         ldaa    input    ;Get input data into ACCA
         tab              ;Put the same number into ACCB
         aba              ;Add the number to itself (multiply by two)
         staa    result+1 ;Save the result
         swi              ;End program (return to monitor in HC12)



DATA:    section .data    ;The stuff which follows is data
         org     data
input:   dc.b    $07      ;first input data
result:  ds.b    2        ;reserve two bytes for results


  
Figure 2: An assembly language program used to get started with the CA6812, ZAP, and D-Bug 12.

Question to answer before lab: What are the contents of the A register after each instruction of the program shown in Figure 2 executes?

We will use D-Bug 12 to explore the memory of the HC12 on your EVBU. The memory map for your 68HC12 is shown on page 31 of the MC68HC912B32 Technical Summary. Most of this memory is used by the D-Bug 12 monitor. Page 3-55 of the M68EVB912B32 Evaluation Board User's Manual shows the memory available for your use.

Question to answer before lab: How many bytes of RAM are available for your use on the EVBU?

Type the program shown in Figure 2 before coming to lab and save it under the name lab02.s. (You can also use a web browswer to download the program.)

Also create the file lab02.lkf which contains the following lines:

# Link file for program lab02.s
+seg .text -b 0x0800 -n .text   # program start address
+seg .data -b 0x0900 -n .data   # data start address
lab02.o                         # application program

You can assemble the at home, using the demo ca6812 assembler with the commands

> ca6812 -a -l -xx -pl lab02.s
> clnk -o lab02.h12 -m lab02.map lab02.lkf
> chex -o lab02.s19 lab02.h12

The ca6812 command will create a file called lab02.o which contains the machine codes in a special form which other programs can read. It also creates the file lab02.ls which shows what op codes were generated by the assembler. The clnk command will translate the lab02.o file into a form which the ZAP simulator can understand. It also creates a file lab02.map which shows where in memory the program will be loaded. The chex command will create a .s19 file, which is the file you will use with the HC12 evaluation board.

Bring a disk with the program on it to the lab.

As you gain experience you will operate independently in the lab. However, for the first few labs you should be pestering the lab assistants to distraction to make sure you get everything that you can from the time in the lab. We are there to help. Your part is to take the pre-lab seriously and show up for the lab session prepared.

The Lab

Create a directory for this course (say, D:\EE308). Inside this directory create a subdirectory for this lab (say, D:\EE308\LAB02). Change to this subdirectory, type in the lab02.s program, and assemble it with the commands shown above.

Some questions on the output of the assembler:

Start the ZAP simulator.

Once you are in the simulator, load the .h12 file using the File menu.

Go to the Show menu and click on Memory. Give a starting address of 0x0800 and a Data format. For Size select Byte. Adjust your desktop so you can see the Registers, Disassembly, Command, and Memory windows. In the Disassembly window you should see the lab01 program.

Question

Trace, or single step, through your program using the istep command in the command window, or clicking on the Footstep icon, and observe what is going on in the Disassembly and Register windows.

When you are done single stepping, do the following:

Check that you have the expected values in result and result + 1 after the program has finished.

Change the input data from $07 to $be, and rerun the program. Check the results.

Some questions on the simulator:

Exit the ZAP simulator when you have finished. Connect your EVBU to your computer and power supply as you did in last week's lab, and power up your HC12.

To download your program to your EVBU type LOAD at the D-Bug 12 prompt. Then select the Transfers menu, Send Text File submenu, and select the file lab02.s19 to send. Wait for the HC12 to respond with >.

Using your EVBU do the same things that you did on the simulator, and answer all of the questions from the simulator section that are applicable to the EVBU. In addition:

Answer the following questions about the EVBU:



Bill Rison, <rison@ee.nmt.edu >
Fri Jan 22 1999

© 1999, New Mexico Tech