...
When executing the assembler from the command line without options, i.e. mpm<ENTER>, a help page is automatically displayed where after control is returned to the operating system command line. The page shortly explains the syntax of option specification and which options are available.
The syntax of the assembler options is a straightforward design. Filenames or a project file are always specified. The options may be left out (surrounded here with []):
mpm [-options] {filenames} | @projectfile
As seen above [-options] must be specified first, followed by the names of assembler source files. You either choose to specify all file names or a @<projectfile> containing all file names. Filenames may be specified with or without the .asm filename extension. At least on source file must be specified and may be repeated with several file names. Only one project file may be specified if no source file names are given. You may use comment lines inside projects files using semicolon.
Options are used to control the assembly process and output. They are recognized by the assembler when you specify a leading minus before the option identifier ('-'). When the assembler is executed options are all preset with default values and are either switched ON or OFF (active or not).
Upper and lower case letters are distinguished, which means that 'a' is a different command than 'A'. If an option is to be turned off, a 'n' is specified before the identification, e.g. -nl
. Single letter options without parameters can be concatanated in a single option block.
Default options are: -sm -nvadbctgA
Environment variables
The assembler looks into the operating system environment for these three variables. Convenient for shell scripts where the environment variables are instantiated for use while the shell is open:
MPM_Z80_INCLUDEPATH | Defines the default path of header/include definition files. Multiple paths may specifed using operating system specific path separator (see options above). Equivalent to the -I option |
MPM_Z80_LIBPATH | Defines the default seach path for Mpm library files. Multiple paths may specifed. Multiple paths may specifed using operating system specific path separator (see options above). Equivalent to the -L option. |
MPM_Z80_STDLIBRARY | Defines the default filename of the standard library to be scanned by LIB directives. |
MPM module assembler file types
The MPM Module Assembler uses several different file name extensions to distinguish the type of files processed and generated. All extensions are using three letter combinations. All generated files will replace the 'asm' extension with the appropriate default output extension (keeping remaining input filename intact).
asm | The source file (input) extension. May be overridden using the -e option. |
obj | The generated object module extension. The file contains intermediate generated machine code, optional address origin, symbols and expressions. May be overridden using the -M option. |
err | Error reporting files. If any errors should occur, they will be written to this file containing information of where the error occurred in the corresponding source file. |
lst | Listing file. This file contains a hexadecimal output column of the generated machine code that corresponds to the Z80 mnemonic instruction or directive, followed by a copy of the original source code, line by line. A symbol table is dumped at the end of the listing file. |
sym | Symbol Table file. This file contains a symbol name and hexadecimal value output columns of the found and used symbol definitions in the sources. The symbol table file is automatically generated if no listing file was enabled. This file is generated by default. |
bin | The final output file containing the executable linked and address relocated object modules. The complete filename (including extension) may be overridden using the -o option. |
map | This file contains a list of all defined address labels from all linked/relocated modules (and optionally LIB modules) with their calculated (absolute) address when the code is loaded into the executing memory environment. All labels are sorted in two sections; first by name, then by address, both in ascending order. |
crc | This file contains a calculated CRC32 hexadecimal value of the final executable output file. It is only generated if you use the -crc32 command line option. |
def | This file contains a DEFC directive list of all globally declared address labels with their calculated (absolute) origin address, fetched only during assembly of source file modules. The file may be useful for cross referencing in separate compile projects. |
lib | Library file, which may be created using the -x option. Library modules may be included into application code during linking of object modules using the -l option. |
The standard platform identifier
When the MPM Assembler is running, a standard platform identifier (with value 1) is made available when typically using IF directives or other expressions. The identifier reflects the name of the platform:
"MSDOS" - the assembler is running on the MS-DOS or Windows platform of computers
"UNIX" - the assembler is running on the LINUX/UNIX/MAC OSX platform.
The identifier might be very handy when you need to port your source files to different computer platforms.
Source file structure and layout
The composition of a source file module is completely free to the programmer. How he chooses to place the source code on a text line has no effect of the parsing process of the assembler. The linefeed interpretation is also handled by MPM - it understands all known line ending formats:
<LF> (used by UNIX/AMIGA/MAC OS X)
<CR><LF> (used by MSDOS, WINDOWS)
<CR> (used by Z88, Mac OS 8/9)
Each source file begins with a MODULE definition, then optionally an ORG directive followed by INCLUDE directives (importing constant definitions). Also appropriate is to specify all global and external identifiers (for cross-module referencing) at the top of the source file, using the XDEF and XREF directives. Good practice is also to specify in which module (file) the XREF identifier is created (where it is XDEF'ined). The rest of the file contains the actual code or data.
Comments in source files
Comments in Z80 source files are added using a semicolon, followed by the text of the comment. When the assembler meets a semicolon the rest of the current source line is ignored until the linefeed. The semicolon may be placed anywhere in a source line. The following is an example on how to use comments in Z80 source files:
Code Block | ||
---|---|---|
| ||
; ********************** ; main menu ; mainmenu: xor a ret ; back to calling routine... |
Defining symbolic address labels
The main reason for using an assembler is to be able to determine symbolical addresses and use them as reference in the code, instead of absolute addresses. These are defined by a name preceded with a full stop or ending with a colon. It is allowed to place an instruction mnemonic or directive after an address label on the same line. An address label may be left as a single statement on a line - you may of course use comment after the label:
Code Block |
---|
mainmenu: xor a .mainmenu2 ; another comment |
It is not allowed to position two label definitions on the same line. However, you may place as many label definitions after each other on separate lines - even though no code is between them. They just receive the same assembler address during compilation. It is not possible to use two identical address labels in the same source file. All labels and constant names are case insensitive.
Using expressions
Expressions is a necessary tool in source files. They define and explain things much clearer than just magic numbers. The MPM Module Assembler allows expressions wherever a parameter is needed, even when a constant is defined. This applies to Z80 mnemonic instructions, directives and even in character strings. The resulting value from an evaluated expression is always an integer. All expressions are calculated as 32 bit signed integers. However, the parameter type defines the true range of the expression. For example, you cannot store a 32 bit signed integer in an 8 bit LD instruction like LD A, n.
If a parameter is outside an allowed integer range an assemble error is reported. Expressions may be formed as arithmetic and relational expressions. Several components are supported: symbol names (identifiers), constants, ASCII characters and all the usual suspects of arithmetic operators.
Numeric constants
Apart from specifying decimal integer numbers, you are allowed to use hexadecimal constants, binary constants and ASCII characters. The following definitions are available:
Digits without leading or trailing specifiers are interpreted as decimal constants.
Decimal | 456567, 456d |
Hexadecimal | $8000, 0xC000 (49152), or 4000h |
Binary | @11000000 (192d) or 1011b (11d) |
Ascii | 'A' (65d) |
...