User’s Manual MCUez HC12 Assembler
28 General Information MOTOROLA
General Information
1.4.2 Creating an Assembly Source File
Once the project has been configured, writing the application can begin. For
example, source code may be stored in a file named test.asm and may look as
like this:
XDEF entry ; Make the symbol entry visible for
; external module.
; This is necessary to allow the
; linker to find the symbol and
; use it as the entry point for
; the application.
initStk: EQU $AFE ; Initial value for SP
dataSec: SECTION ; Define a section
var1: DC.W 5 ; Assign 5 to the symbol var1
codeSec: SECTION ; Define a section for code
entry:
LDS #initStk ; Load stack pointer
LDD var1
BRA entry
When writing assembly source code, pay special attention to these points:
• All symbols referenced outside the current source file (in another source
file or in the linker configuration file) must be visible externally. For this
reason, the assembly directive XDEF entry has been inserted.
• To make debugging from the application easier, defining separate
sections for code, constant data (defined with DC (define constant)), and
variables (defined with DS (define space)) are strongly recommended.
This enables the symbols located in the variable or constant data sections
to be displayed in the data window component of the debugger.
• The stack pointer must be initialized when using BSR (branch to
subroutine) or JSR (jump to subroutine) instructions in an application.