Skip to main content
Untitled Document

Assembly

Assembly

Assembly

When all else fails, one can resort to inline assembly. This can be in the form of a single statement:

          ASM ...

or an entire block:

          ASSEMBLER
             statements
          END ASSEMBLER

Using assembly should be a last resort -- it is needed only when either a feature is not possible using JALv2 (for example, the TRIS and OPTION codes), or when speed is of the essence. JALv2 includes the entire assembly language set in the PIC16F87x data sheet, several instructions from earlier micro controllers, and several common macros. There is some support for the 16 bit keywords.

To guarantee the correct data bank is selected when accessing a file register, use one of the following:

          BANK opcode ...

Or:

          BANK f

The former takes the file register from the command, the later takes it directly.

Similarly, to guarantee the correct page bits are set (for GOTO or CALL), use one of the following:

          PAGE opcode ...

Or:

          PAGE lbl

Again, the former takes the label from the command, the later takes it directly.

Normally, the codes to set or clear the bank or page bits are only generated when necessary. If the bits are already in the correct states, no further commands are generated. If you need to guarantee the codes are always generated, use the following pragmas:

          PRAGMA KEEP PAGE
          PRAGMA KEEP BANK

The former will keep any page bits, the later and bank bits. These affect the entire sub-program in which they are declared.

To declare a local label for use in CALLs and/or GOTOs:

          LOCAL identifier[',' identifier2...]

Once declared, a label is inserted into the assembly block by making it the first part of a statement, followed by a ':':

          identifier: opcode...

The available opcodes are listed below. For a full description see the appropriate data sheet.

Note that when using inline assembly you should not modify the bank or page registers, FSR, or BSR. If these are modified, it is the programmers responsibility to return them to their original states.