- Introduction
- Comments
- Expressions
- Labels
- Precompiler Directives
- Pseudo-Opcodes
- HCS12 Opcodes
- Output Files
Introduction
The HSW12ASM is a simple multi-pass assembler which has been written in Perl code. Some features of this assembler are:- It handles 16MB of address space
- It generates linear and paged S-Record files
- It uses two program counters (linear and paged) to control the S-Record output
- It exports source code symbols into the HSW12 IDE
Comments
All code following ";" to the end of the line is interpreted as a comment by the HSW12 assembler. Comments may also begin with an "*" if it is the first non-whitespace character in the line.Expressions
Expressions consist of symbols, constants and operators. They are used as operands for the HC(S) opcodes and and the assembler pseudo opcodes.Symbols
Symbols represent integer values.User Defined Symbols
Symbols can be defined through various pseudo-opcodes or through the use of labels. A symbol name must comply to these rules:- The symbol name must consist of alpha-numeric characters, and underscores (^[A-Z0-9_]+$)
- The symbol name must begin with a letter (^[A-Z])
- The symbol name may not contain any whitespaces
- The symbol name may not be any of the keywords: A, B, D, X, Y, SP, CCR, PC, TMP2, TMP3, UNMAPPED
Predefined Symbols
The HSW12 assembler knows a set of predefined symbols:Automatic Symbol Extensions
The HSW12 assembler supports the automatic generation of symbol name extensions. If a symbol name ends with a "'", this character will be substituted by the contents of the LOC counter variable. This counter may be incremented by the LOC pseudo-opcode.Constants
Integer Constants are of the following format:Operators
The HSW12 assembler supports the operators that are listed below (from highest to lowest precedence). Expressions may be nested in parenthesis.Labels
Labels assign the current value of the paged program counter to a symbol. The syntax is:To assign the current value of the linear program counter to a symbol, use the following syntax:
Precompiler Directives
The HSW12 assembler knows the following precompiler directives: All precompiler directives must comply to the following syntax rules:#DEFINE
Sets an assembler define for conditional code compilation. All assembler defines will be exported into compiler symbols at the end of the precompile step."#DEFINE" requires two arguments:
- a define name
- a value the define is set to (optional)
#UNDEF
Undefines an assembler define."#UNDEF" requires one argument:
- a define name
#IFDEF
Starts a section of conditional code. This code will only be compiled if the define is set.#IFNDEF
Starts a section of conditional code. This code will only be compiled if the define is not set.#IFMAC
Starts a section of conditional code. This code will only be compiled if the macro is defined.#IFNMAC
Starts a section of conditional code. This code will only be compiled if the macro is not defined.#ELSE
Ends a section of conditional code that has been initiated with "#IFDEF", "#IFNDEF", "#IFMAC", or "#IFNMAC" and starts a new one that requires the opposite condition.#ENDIF
End a section of conditional code.#INCLUDE
Includes a source code file at the current position.#MACRO
Starts a macro definition. This directive requires two arguments:- The macro name
- The number of arguments which are to be passed to the macro
Example:
#EMAC
Ends a macro definition.Pseudo-Opcodes
The following pseudo-opcodes are supported by the HSW12 assembler:- ALIGN
- CPU
- DC.B (DB, FCB)
- DC.W (DW, FDW)
- DS.B (DS, RMB)
- DS.W (RMW)
- ERROR
- EQU
- FCC
- FCS
- FCZ
- FILL
- FLET16
- LOC
- ORG
- UNALIGN
- SETDP
All pseudo-opcodes must comply to the following syntax rules:
ALIGN
Increments both program counters until PC & mask == 0. If a second argument is given, then all memory locations in between are filled with the lower eight bit of this integer.Syntax:
CPU
Switches to a different opcode table. Supported CPUs are:- HC11 (untested)
- HC12
- S12
- S12X
- XGATE
DC.B (DB, FCB)
Writes a number of constant bytes into the memory.Syntax:
DC.W (DW, FDW)
Writes a number of constant words into the memory.Syntax:
DS.B (DS, RMB)
Advances both program counters by a number of bytes.Syntax:
DS.W (RMW)
Advances both program counters by a number of words.Syntax:
ERROR
Triggers an intentional compile error. The string must be surrounded by a delimiter which can be any character.Syntax:
EQU
Directly assigns a value to a symbol.Syntax:
FCC
Writes an ASCII string into the memory. The string must be surrounded by a delimiter which can be any character.Syntax:
FCS
Writes an ASCII string into the memory, which is terminated by a set MSB in the last character. The string must be surrounded by a delimiter which can be any character.Syntax:
FCZ
Writes an ASCII string into the memory, which is terminated by a zero character ($00). The string must be surrounded by a delimeter which can be any character.Syntax:
FILL
Fills a number of memory bytes with an 8-bit pattern.Syntax:
FLET16
Calculates the Fletcher-16 checksum of a paged address range (defined by the two arguments: start address and end address).Syntax:
LOC
Increments the "LOC" counter that is used for automatic symbol name extensions.Syntax:
ORG
This pseudo-opcode can be used to set the program counters to a certain value. If "ORG" is called with two arguments, then the paged program counter will be set to the value of the first argument. The linear program counter will be set to the value of the second argument. If only one argument is passed to the pseudo-opcode, then this one will be the new value of the paged program counter. The value of the linear program counter is determined by the following table.Paged Program Counter | Linear Program Counter |
---|---|
xx0000 to xx3FFF |
F4000 to F7FFF |
xx4000 to xx7FFF |
F8000 to FBFFF |
xx8000 to xxBFFF |
(xx*4000) to (xx*4000+3FFF) |
xxC000 to xxFFFF |
FC000 to FFFFF |
Syntax:
UNALIGN
Same as ALIGN, except that the program counters are incremented until PC & mask == mask.Syntax:
SETDP
Selects the 256 byte address range in which direct address mode can be applied for S12X MCUs.Syntax:
HCS12 Opcodes
For a description of the HC(S)12 instruction set, please refer to the HCS12 Core Guide.All opcodes must comply to the following syntax rules:
Output Files
The HSW12 assembler can generate three output files:- A Code Listing
-
The Code Listing shows the assembler source together with the associated hex code. The entries are sorted by their paged address.
- A Paged S-Record File
-
The hex code of the paged address domain (paged program counter) in Motorola's S-Record format.
Paged addresses consist of an 8-bit page value (PPAGE register, MSB) and a 16-bit address value (PC register, LSB) =>PPAGE:ADDR.
- A Linear S-Record File
-
The hex code of the linear address domain (linear program counter) in Motorola's S-Record format.
Linear addresses are equivalent to the physical address space of the NVMs inside the HC(S)12 MCUs.