Assembler Input/Output Files

MPASM Assembler

Assembler Input/Output Files

These are the default file extensions used by the assembler and the associated utility functions.

Table: Input Files
Default source file extension input to assembler.
Include (header) file
Table: Output Files
Default output extension for listing files generated by assembler.
Output extension from assembler for error files.
Output extension from assembler for hex files.
Output extension for the symbol and debug file. This file may be output from assembler or MPLINK linker.
Output extension from assembler for object files.

Source Code (.asm)

Assembly source code is one programming language you may use to develop your application. The source code file may be created using any ASCII text file editor. It should conform to the following basic guidelines.

Each line of the source file may contain up to four types of information:

The order and position of these are important. Labels must start in column one. Mnemonics may start in column two or beyond. Operands follow the mnemonic. Comments may follow the operands, mnemonics or labels, and can start in any column. The maximum column width is 255 characters.

Whitespace or a colon must separate the label and the mnemonic, and the mnemonic and the operand(s). Multiple operands must be separated by a comma.

Sample MPASM Assembler Source Code (Shows multiple operands)

;

; Sample MPASM Source Code. For illustration only.

;

list p=16c54

Dest equ H'0B'

org H'01FF'

goto Start

org H'0000'

Start movlw H'0A'

movwf Dest

bcf Dest, 3

goto Start

end

Labels

A label must start in column 1. It may be followed by a colon (:), space, tab or the end of line.

Labels must begin with an alpha character or an under bar (_) and may contain alphanumeric characters, the under bar and the question mark.

Note: Do not use labels with a leading underscore and number, e.g., _2NDLOOP. Also, do not use the assembler reserved word Halt as a label.

Labels may be up to 32 characters long. By default they are case sensitive, but case sensitivity may be overridden by a command line option. If a colon is used when defining a label, it is treated as a label operator and not part of the label itself.

Mnemonics

Assembler instruction mnemonics, assembler directives and macro calls must begin in column two or greater. If there is a label on the same line, instructions must be separated from that label by a colon, or by one or more spaces or tabs.

Operands

Operands must be separated from mnemonics by one or more spaces, or tabs. Multiple operands must be separated by commas.

Comments

MPASM assembler treats anything after a semicolon as a comment. All characters following the semicolon are ignored through the end of the line. String constants containing a semicolon are allowed and are not confused with comments.

Include File (.inc)

Assembler include, or header, file. Usually contains device-specific register and bit assignments.

As an example, to add the standard header file for the PIC18F452 device to your assembly code, use:

#include <p18f452.inc>

Listing File (.lst)

A listing file provides a mapping of source code to machine instructions. MPASM assembler and MPLINK linker can generate listing files.

Sample MPASM Assembler Listing File

The product name and version, the assembly date and time, and the page number appear at the top of every page.

The first column of numbers contains the base address in memory where the code will be placed. The second column displays the 32-bit value of any symbols created with the SET, EQU, VARIABLE, CONSTANT, or CBLOCK directives. The third column is reserved for the machine instruction. This is the code that will be executed by the PICmicro MCU. The fourth column lists the associated source file line number for this line. The remainder of the line is reserved for the source code line that generated the machine code.

Errors, warnings, and messages are embedded between the source lines and pertain to the following source line.

The symbol table lists all symbols defined in the program. The memory usage map gives a graphical representation of memory usage. 'X' marks a used location and '-' marks memory that is not used by this object. The memory map is not printed if an object file is generated.

MPASM 01.99.21 Intermediate MANUAL.ASM 5-30-1997 15:31:05 PAGE 1

LOC OBJECT CODE LINE SOURCE TEXT

VALUE

00001 ;

00002 ; Sample MPASM Source Code. For illustration only.

00003 ;

00004 list p=16c54

0000000B 00005 Dest equ H'0B'

00006

01FF 00007 org H'01FF'

01FF 0A00 00008 goto Start

00009

0000 00010 org H'0000'

00011

0000 0C0A 00012 Start movlw H'0A'

0001 002B 00013 movwf Dest

0002 0A00 00014 goto Start

00015

00016 end

MPASM 01.99.21 Intermediate MANUAL.ASM 5-30-1997 15:31:05 PAGE 2

SYMBOL TABLE

LABEL VALUE

Dest 0000000B

Start 00000000

__16C54 00000001

MEMORY USAGE MAP ('X' = Used, '-' = Unused)

0000 : XXX------------- ---------------- ---------------- ----------------

01C0 : ---------------- ---------------- ---------------- ---------------X

All other memory blocks unused.

Program Memory Words Used: 4

Program Memory Words Free: 508

Errors : 0

Warnings : 0 reported, 0 suppressed

Messages : 0 reported, 0 suppressed

Error File (.err)

MPASM assembler, by default, generates an error file. This file can be useful when debugging your code. The MPLAB IDE Source Level Debugger will automatically open this file in the case of an error. The format of the messages in the error file is:

<type>[<number>] <file> <line> <description>

For example:

Error[113] C:\PROG.ASM 7 : Symbol not previously defined (start)

The error file will contain MPASM assembler errors, warnings and messages.

Hex File Formats (.hex, .hxl, .hxh)

MPASM Assembler is capable of producing different hex file formats.

Format Name
Format Type
File Extension
Use
INHX8M
.HEX
for standard programmers
INHX8S
.HXL, .HXH
for odd/even ROM programmers
INHX32
.HEX
for 16-bit core programmers

Intel Hex Format

This format produces one 8-bit hex file with a low byte, high byte combination. Since each address can only contain 8 bits in this format, all addresses are doubled. This file format is useful for transferring PICmicro MCU series code to PRO MATE II, PICSTART Plus and third party PICmicro MCU programmers.

Each data record begins with a 9-character prefix and ends with a 2-character checksum. Each record has the following format:

:BBAAAATTHHHH....HHHCC

where:

BB - is a two digit hexadecimal byte count representing the number of data bytes that will appear on the line.

AAAA - is a four digit hexadecimal address representing the starting address of the data record.

TT - is a two digit record type record type that will always be '00' except for the end-of-file record, which will be '01'.

HH - is a two digit hexadecimal data byte, presented in low-byte/high-byte combinations.

CC - is a two digit hexadecimal checksum that is the two's complement of the sum of all preceding bytes in the record.

Example

<file_name>.HEX

:1000000000000000000000000000000000000000F0

:0400100000000000EC

:100032000000280040006800A800E800C80028016D

:100042006801A9018901EA01280208026A02BF02C5

:10005200E002E80228036803BF03E803C8030804B8

:1000620008040804030443050306E807E807FF0839

:06007200FF08FF08190A57

:00000001FF

Intel Split Hex Format

The split 8-bit file format produces two output files: .HXL and .HXH. The format is the same as the normal 8-bit format, except that the low bytes of the data word are stored in the .HXL file, and the high bytes of the data word are stored in the .HXH file, and the addresses are divided by two. This is used to program 16-bit words into pairs of 8-bit EPROMs, one file for Low Byte, one file for High Byte.

Example

<file_name>.HXL

:0A0000000000000000000000000000F6

:1000190000284068A8E8C82868A989EA28086ABFAA

:10002900E0E82868BFE8C8080808034303E8E8FFD0

:03003900FFFF19AD

:00000001FF

<file_name>.HXH

:0A0000000000000000000000000000F6

:1000190000000000000000010101010102020202CA

:100029000202030303030304040404050607070883

:0300390008080AAA

:00000001FF

Intel Hex 32 Format

The extended 32-bit address hex format is similar to the hex 8 format, except that the extended linear address record is output also to establish the upper 16 bits of the data address. This is mainly used for 16-bit core devices since their addressable program memory exceeds 32 kwords.

Each data record begins with a 9-character prefix and ends with a 2-character checksum. Each record has the following format:

:BBAAAATTHHHH....HHHCC

where:

BB - is a two digit hexadecimal byte count representing the number of data bytes that will appear on the line.

AAAA - is a four digit hexadecimal address representing the starting address of the data record.

TT - is a two digit record type:

00 - Data record

01 - End of File record

02 - Segment address record

04 - Linear address record

HH - is a two digit hexadecimal data byte, presented in low byte, high byte combinations.

CC - is a two digit hexadecimal checksum that is the two's complement of the sum of all preceding bytes in the record.

Symbol and Debug File (.cod)

A COD file is used by MPLAB IDE to debug code. The COD file name, including the path, has a 63 character limit. MPASM assembler and MPLINK linker can generate a COD file.

Object File (.o)

Object files are the relocatable code produced from source files.

  • MPASM assembler assembles source files into object files.
  • MPLINK linker combines object files and library files, according to a linker script, into a single output file.
  • MPLIB librarian combines several object files into a single library file.

  • Microchip Technology Inc.
    Microchip's Web Site
    Voice: (480) 792-7200
    Fax: (480) 899-9210
    Microchip's E-mail Address
    PreviousNext