PICASM User Manual

For the PICASM Assembler for the Microchip PIC




This is a replication of the User Manual which is included with the PICASM Distribution Archive. It is provided here as an online reference, and as a guide to the capabilities and functionality of the PICASM Assembler for the Microchip PIC.


Contents

Overview

Command Line Invokation

Syntax

Directives

Numbers

Expressions

String Expressions

Native Opcodes

Enhanced Opcodes

Output Files


Overview

Meaning

kexpr expr sexpr


Command Line Invokation

Switches

Output Files

Use With ICEbreaker


Syntax

Labels

@ Labels

? Labels

Statements

Comments

Differences To MPASM

There are numerous differences in what PICASM will accept and what MPASM will, however, many source files for MPASM will compile without alteration; this is based upon a selection of real source code examples run through PICASM. These code examples have been created by third parties without knowledge of PICASM and are therefore representative of code which is actually being written, rather than what MPASM supports.

MPASM is a very comprehensive assembler, and I have no hesitation in recommending it if you wish to use the native instruction set only. MPASM does not however support the same enhanced instruction set that PICASM does, and the penalty for using the enhaced instruction set ( or PICASM at all ) is a divergence away from the MPASM standard.

The important places where changes may need to me made to the source are as follows -

MACRO

    The syntax of the MACRO directive has changed, as has the means of handling arguments passed into the MACRO. Please see the section on the MACRO directive for full details of the new use.

LOCAL

    Local labels are no longer declared using the LOCAL directive, but are defined by prefixing the label with a question mark ( '?' ). Labels so defined will be local to the MACRO within which they are declared, or the source file within which they appear.

LIST

    Many options ignored.

RADIX and Number Format

    The RADIX directive is no longer supported. All numbers are deemed to be decimal unless they have been defined using a radix overide ( H'..' etc ), and when the enhanced assembly mode has not been selected, all numbers which start witha zero ( '0' ) are deemed to be hexadecimal.

END

    The end directive is simply ignored when the native assembly option is selected.


Directives

PROCESSOR

HIDDEN

LIST

NOLIST

INCLUDE

IF

IFDEF

Shorthand version of IF DEFINED(sexpr).

IFNDEF

Shorthand version of IF NOT DEFINED(sexpr).

SELECT

There are two type of SELECT statements; SELECT and SELECT CASE. Both are terminated by ENDSELECT or END SELECT and enclose a number of CASE statements.

The SELECT statement will chose to assemble the code preceeded by the CASE statement which yields a true ( non-zero ) result.

        A       EQU     2

                SELECT
                  CASE A = 1
                    DATA "A is 1"
                  CASE A = 2
                    DATA "A is 2"
                  CASE ELSE
                    DATA "A is neither 1 or 2"
                END SELECT

Only one CASE must evaluate true ( non-zero ) in a SELECT statement.

The CASE ELSE statement will be executed if no other CASE match has occured.

The CASE ELSE statement cannot be followed by any subsequent CASE statements.

The "CASE" in a SELECT CASE is optional, SELECT followed by an expression is treated as a SELECT CASE.

SELECT CASE

There are two type of SELECT statements; SELECT and SELECT CASE. Both are terminated by ENDSELECT or END SELECT and enclose a number of CASE statements.

The SELECT CASE statement will chose to assemble the code perceeded by the CASE statement whose result matches the expression specified at the end of the SELECT CASE satement

        A       EQU     2

                SELECT CASE A
                  CASE 1
                    DATA "A is 1"
                  CASE 2
                    DATA "A is 2"
                  CASE ELSE
                    DATA "A is neither 1 or 2"
                END SELECT

Only one CASE must match with the expression in a SELECT CASE statement.

The CASE ELSE statement will be executed if no other CASE match has occured.

The CASE ELSE statement cannot be followed by any subsequent CASE statements.

The "CASE" in a SELECT CASE is optional, SELECT followed by an expression is treated as a SELECT CASE.

MACRO

EQU

label EQU expr regbit EQU reg,{-}bit regbit EQU regbit reg EQU REG reg

SET

REG / RES / DIM

reg REG { size } { @ address } reg REG EQU reg

DATA

The DATA statement is used to store numbers and strings within the code space.

The data statement is followed by one or more expressions and strings, each separated by commas.

Each number is stored as a single word.

Each string has its separate characters stored in the order in which they appear in the string.

A string may be PACKED, in which case two characters are stored in each word if the opcode size is 14-bits or more. The first character of the string is stored in the msb part of the word, the next in the lsb and so on. The string will be padded with a NULL (zero) character if it has an odd number of characters. Strings are not NULL terminated except when explicitly specified as such by the user.

If the opcode size is 14 or 15 bits, the characters will be truncated to 7-bit by ignoring the msb of each character and will be aligned to use the 14 lsb's of the opcode word.

END

MODULE

ORG

/

Directives can be specified at the command line or in the source code by using /option.

Whether an option has been set or not can be determined by using the DEFINED symbol function. The option must be enclosed in quotes,

        IF DEFINED "/LOCAL"
          DATA "/LOCAL set"
        ELSE
          DATA "/LOCAL not set"
        END IF

        IFDEF "/LOCAL"
          DATA "/LOCAL set"
        ELSE
          DATA "/LOCAL not set"
        END IF

Note that not enclosing the variable name you are checking for in quotes will cause a confusing, but correct, error message

        IF DEFINED FRED
                   ^ Not defined (FRED)

/NATIVE Allow Microchip native opcode assembly /ENHANCED ALLOW ENHANCED OPCODE ASSEMBY /LIST:ALL SHOW EVERYTHING IN LISTING /LIST:SYSTEM SHOW SYSTEM SYMBOL TABLE /LIST:BALANCE SHOW SYMBOL TABLE BALANCE /LIST:CODE SHOW ASSEMBLED CODE IN LISTING /LIST:NATIVE SHOW NATIVE OPCODE LIST IN LISTING /PASS2 FORCE PASS2 PROCESSING EVEN IF ERRORS /FILE:SYM PRODUCE .SYM FILE /NOTIDY DON'T DELETE TEMPORARY FILES AT END OF COMPILATION /ICEBREAKER MODIFY TARGET TO TAKE INTO ACCOUNT IT'S RUNNING ON ICEBREAKER /ICD Allw ICD registers etc to be used /NOHEX NO HEX OUTPUT FILE /PROCESSOR:cpu TYPE OF CPU ( READ ONLY )


Numbers

Enhanced Number Format

Native Number Format


Expressions

Variables

Pre-Defined Number Variables

* Current PC

Variable Indexing

expr[kexpr]

Binary Operators

Unary Operators

USED("name") This is used to determine if the named label or variable has been referenced in the program but has not been defined. This is extremely useful when writing library functions based upon whether a call has been made to a function of not, allowing library files to only include code which has been referenced.

        BSR     MyLib

        ; More code

        IF USED("MyLib")

MyLib:
        ; Perform the actions required by MyLib
        RTS

        END IF

The MyLib code from the library will only be included if the program references MyLib and it hasn't been defined within the program before the library code is referenced.


String Expressions

String Variables

Pre-Defined String Variables

DATE$ TIME$ TITLE$ FILE$

Binary String Operators

Unary String Operators


Native Opcodes


Enhanced Opcodes

Pre-Defined Registers

Pre-Defined Bits

Branching Across Page Boundaries


Output Files

.LST - Listing File

.ERR - Error File

.HEX - Object File

.COD - Code Debugging File





Associated Articles

  PICASM Assembler

  PICASM Assembler Opcodes



Site Navigation

  Home Page
  What's New
  Search
  Add Bookmark
  Have Your Say
  Guestbook



The PICASM Assembler © 2002-2004, The Happy Hippy


First published on Sunday the 17th of November, 2002 at 16:47:34
Last upload was on Thursday the 8th of January, 2004 at 14:07:32