Multiple Directive Example 2

MPASM Assembler

Multiple Directive Example 2

Directives highlighted in this example are:

  • #define
  • #undefine
  • equ
  • constant
  • variable
  • set
  • Program Functional Description

    This program performs several calculations using definded constants and variables. As in control directives - example 1, processor is used to specify the processor type, radix is used to specify the radix used, and #include is used to include a header file. See example 1 for more on these directives.

    Commented Code Listing

    ;**************************************

    ;* MPASM Assembler Control Directives *

    ;* Example Program 2 *

    ;* Perform calculations *

    ;**************************************

    processor 16f877 ;Set the processor

    radix hex ;Set the radix

    #include <p16f877.inc> ;Include header file

    #define Tdistance1 50 ;Define the symbol

    ;Tdistance1

    #define Tdistance2 25 ;Define the symbol

    ;Tdistance2

    #undefine Tdistance2 ;Remove Tdistance2 from

    ;the symbol table

    distance_reg equ 0x20 ;Set up distance_reg

    ;at GPR 0x20

    org 0x00 ;Reset Vector

    goto Start

    org 0x06 ;Start Program

    Start

    movlw Tdistance1 ;Move value of Tdistance1

    movwf distance_reg ;into distance_reg

    constant distance1=10 ;Declare distance1

    ;a constant symbol

    variable distance2 ;Declare distance2

    ;a variable symbol

    distance3 set 10 ;Define a value for

    ;the symbol distance3

    Set symbol distance3 to 10.

    distance2=15 ;Give distance2 an

    ;initial value

    distance2=distance1+distance2 ;Add distance1

    ;to distance2

    distance3 set 15 ;Change value of distance3

    distance2=distance2+distance3 ;Add distance3

    ;to distance2

    movlw distance2 ;Move value of distance2

    movwf distance_reg ;into distance_reg

    end

    Additional Comments

    Using Watch Windows

    Once the program begins, the value of Tdistance1 is placed into distance_reg. This can be observed in a watch window, where the value of distance_reg will become 50. The symbol Tdistance1 will not be found in the watch window symbol list, as symbols defined using the #define directive are not available for viewing in MPLAB IDE.

    The final lines of the example program write the final value of distance2 to distance_reg. If you had a watch window open to see distance_reg loaded with the value of 50, you will see it change to 3A. Remember that the radix is hexadecimal, so hex addition was used to determine the distance2 value.

    Looking in the watch window symbol list, you will find the symbols distance1, distance2 and distance3. However, they will have no values. These symbol values are not actually stored on the PICmicro device, but implemented only in the assembler.


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