This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 0306-250
Assembly Language Programming
Laboratory Exercise One: CodeWarrior IDE Tutorial
This exercise introduces the Freescale™ CodeWarrior® IDE (integrated development
environment), which runs on a PC under Windows. The objective of this exercise is
familiarization with the CodeWarrior® programming environment: creating projects,
entering assembly language programs, assembling, simulating, and debugging. An
assembly language program is entered and simulated in the CodeWarrior® IDE.
Assembling Code Using CodeWarrior® IDE
1. Start CodeWarrior IDE: from the Windows desktop, click
StartàProgramsàFreescale CodeWarrioràCW for HC12 V4.5àCodeWarrior IDE. 2. Create a new project: from CodeWarrior main menu, select FileàNew to launch New
window. Do these actions in New window.
a. Select Project tab (default).
b. Highlight HC(S)12 New Project Wizard (default).
c. In Project Name field, type Exercise1.
d. Under Location, use Set button to create a folder for this project.
i. Navigate to your X drive (network drive).
ii. Create a new folder, and name it 20091.
iii. In 20091, create a new folder, and name it 250.
iv. In 250, create a new folder, and name it Exercise1.
v. Open the new Exercise1 folder.
vi. Type Exercise1 for the file name (default).
vii. Click Save.
e. Click OK.
3. Complete New Project Wizard to get to Project Manager window.
a. Click Next on New Project Wizard—Page 1.
b. Select MC9S12DT256B as the derivative your want to use, and click Next.
c. Check Assembly for language support, and click Next.
d. Check Relocatable Assembly, and click Next.
e. Check Full Chip Simulation, check P&E Multilink/Cyclone Pro, and click Finish.
4. Switch to full chip simulation for debugging:
Click the pull-down arrow at the top left of Project Manager window, and select Full
Chip Simulation, as shown in Figure 1. (Note: for this exercise simulation is used for
debugging. To use HCS12 hardware for debugging in future exercises, P&E Multilink
Cyclone Pro will be selected.) Page 1 of 8 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 2 of 8 Figure 1. Project Manager Window
5. Enable creation of listing files.
a. Click on Full Chip Simulation Settings button (shown in Figure 1) to launch
Standard Settings window.
b. In Target Settings Panel at left side of Full Chip Simulation Settings window,
make sure Target folder is open. (Click + next to Target if it is not open.)
c. Under Target, click Assembler for HC12 to open Assembler for HC12 settings.
d. Click Options to open and set HC12 Assembler Options Settings.
i. Check Object File Format, and a box with pull-down arrow will appear below
the check boxes.
ii. Click Object File Format pull-down arrow, and select ELF/DWARF 2.0 Object
iii. Check Generate a listing file.
iv. Check Do not print included files in listing file.
v. Click OK.
e. Click OK.
6. Enter assembly language source code.
a. In the left panel of Project Manager, make sure Sources folder is open. (Click +
next to Sources if it is not open.)
b. Double click main.asm under Sources to open main.asm in code editor window.
c. Save the code to your source file.
i. From the CodeWarrior main menu, select FileàSave As to open the Save As
ii. Type Exercise1.asm in Object name box.
iii. Click Save.
d. Replace the default code with the code shown in Figure 2. Other than changing
the lines in the comment header block where indicated, type the text exactly as
shown—including line spacing and indentation.
e. From the CodeWarrior main menu, select FileàSave to save the edited program. 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 3 of 8 Figure 2. Exercise 1 Assembly Code
7. Enable generation of debugging information.
a. In the left panel of Project Manager, make sure there is a bullet (·) in the debug
column, (i.e., under the green bug icon as shown in Figure 3), for Sources and
Exercise1.asm. (Note: If debugging is not enabled, a warning message that no
debug information has been generated will appear during assembly, and no source
information will appear in the debugger.) 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 4 of 8 Figure 3. Project Manager Debug Enable
8. Assemble Exercise1.
a. From the CodeWarrior main menu, select ProjectàCompile.
b. Building Exercise1.mcp window will appear briefly.
c. If Errors & Warnings window appears, there are errors in Exercise1.asm that must
be corrected for it to be assembled successfully. Otherwise, assembly was
Understanding Assembler Listing Files
9. View the listing file: Exercise1.lst.
a. From the CodeWarrior main menu, select FileàOpen.
b. Navigate to project’s bin folder. (Default will be project’s Sources folder, so
click Up One Level button, and then double-click bin folder.).
c. Select Exercise1.lst and then click Open.
10. Examine the listing file and answer the following questions.
Q1. Why are the memory contents for VarData bytes not shown in the listing file? Q2. Why can the memory addresses for VarData bytes not be determined from the
listing file? Q3. What opcode (in hexadecimal) is generated for the nop instruction? 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 5 of 8 Q4. Do assembly language program labels generate any code bytes? Explain why. Q5. Why does the instruction ldx ConstData assemble to CExx xx? Q6. What are the four bytes (in hexadecimal) assembled as constant data bytes by
the assembler directive DC.B? Q7. In ConstData, why does DC.B produce different byte values for $10 and 10? 11. Show your answers to your lab instructor for signature.
Making Projects Code Using CodeWarrior® IDE
12. View the linker parameter file.
a. In the left panel of Project Manager, make sure Prm folder is open. (Click + next
to Prm if it is not open.)
b. Double click Full_Chip_Simulation_linker.prm under Prm to open the linker
13. Make the project.
a. From the CodeWarrior main menu, select ProjectàMake or click the Make
b. Building Exercise1.mcp window will appear briefly.
c. Any errors that appear must be corrected to continue. Otherwise, the project was
14. View the linker map file.
a. In the left panel of Project Manager, make sure Linker Map folder is open. (Click
+ next to Linker Map if it is not open.)
b. Double click Full_Chip_Simulation.map under Linker Map to open the linker map
file. 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 6 of 8 15. Examine the linker map file and answer the following questions.
STARTUP SECTION Q8. What is the starting address of the program? SECTION-ALLOCATION SECTION
(Note that the MyCode section of the assembly language program shows in the
linker map file as .init, which is a “standard” term used for a C program’s startup code and is also used by CodeWarrior for assembly programs.)
Q9. What number base is used for Size of the various sections? Q10. How many bytes of ROM are used by this program? Q11. How many bytes of RAM are used by this program? OBJECT-ALLOCATION SECTION Q12. What is the memory address of the label main_loop? Q13. What is the memory address of the label loop? Q14. What is the memory address of the label MyData? 16. Show your answers to your lab instructor for signature.
Simulation Using CodeWarrior® IDE
17. Launch the CodeWarrior True-Time Simulator.
a. In the pull-down box at the top left of Project Manager, make sure Full Chip
Simulation is selected (as shown in Figure 2).
b. From the CodeWarrior main menu, select ProjectàDebug , press F5, or click the
button. If a loader warning appears, click OK.
18. Explore the simulator.
a. Source window shows the source program.
b. Assembly window shows the program as it looks in memory.
c. Registers window shows the current contents/status of all registers.
d. Data window shows the current value of constant and variable data in the
program. Clicking + next to a label shows the contents of each constant or
variable associated with that label. Right clicking in this window gives a context
menu with Format, which can be used to change how the contents are displayed.
e. Procedure window shows the current procedure.
f. Command window allows entry of simulator/debugger commands.
g. Memory window allows display of memory contents. To display beginning at a
specific address, right click, select Address to launch Select Address window,
type the address, and click OK.
h. Any of the simulator windows can be resized, moved, minimized, or closed.
19. Run the program in the simulator.
a. In Source window, position mouse pointer over first nop instruction, right click,
and select Set Breakpoint. Setting a breakpoint here will cause program
execution to stop before executing this instruction.
b. In the row of buttons under the True-Time Simulator main menu, click the
Start/Continue ¢ button or select RunàStart/Continue from the main menu. 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 7 of 8 c. Click the Single Step
button or press F11 to execute the current (highlighted)
program instruction. Look at Register window to see the effects of executing the
20. Reset the program and run it again to track all changes to the registers in Table 1.
a. For each of registers D, IX, IY, IP, and SP, double-click its register box in
Register window, and enter a value of zero.
b. Click Reset Target
button or press Ctrl-R to return the program to its initial
c. Single step through the program instructions to record each instruction’s register
changes in Table 1. Note that CCR bits are shown in black if they are set (1) and
grey if they are cleared (0). If an instruction does not change the value of a
register, you may leave its cell in the table blank rather than rewriting the same
Table 1. Register contents after each program instruction
Reset state D A B IX IY PC SP N Z V C 0000 00 00 0000 0000 C000 FFFE 0 0 0 0 lds #__SEG_END_STACK sei
ldx #ConstData ldab #$02 ldaa 0,x staa VarData ldaa 2,x staa VarData+1 inx
bne loop ldaa 0,x staa VarData ldaa 2,x staa VarData inx
bne loop nop 21. Show your completed table to your lab instructor for signature. 0306-250 20091 Lab Exercise 1: CodeWarrior IDE Tutorial Page 8 of 8 Print files to submit with your report.
22. Print your listing file (.lst) and linker map file (.map). Note that you may need to
print them in landscape mode for readability (i.e., full grading credit).
23. Have your instructor sign your printed files.
Write a report consisting of the following sections.
The grading sheet includes specific guidelines for these sections. Your writing should
follow the rules of professional technical writing and should meet the specifications in
“Laboratory and Report Guidelines” on the course reference material web page. Staple
your cover page, report, listing file, and grading sheet (in that order), and submit them at
the beginning of the next lab session. Late reports are penalized 20% per day late, where
“day late” is calculated by rounding submitted time to the nearest greater or equal integer
number of days late (i.e., ceiling function). Freescale™ is a trademark of Freescale Semiconductor, Inc.
CodeWarrior® is a trademark or registered trademark of Freescale Semiconductor, Inc. in the United States
and/or other countries.
Windows is a registered trademark of Microsoft Corporation in the United States and other countries.
This lab exercise is an independent publication and is not affiliated with nor has it been authorized,
sponsored, or otherwise approved by Freescale Semiconductor, Inc., or Microsoft Corporation.
Material in this lab exercise is adapted from “Introduction to CodeWarrior™—Simulating the
Microcontroller in Assembly Language,” www.freescale.com/universityprograms, Document
LABS12CINTRO03 /REV 1, 2006. ...
View Full Document
- Fall '10