VARIABLE/CONSTANT Example

MPASM Assembler

VARIABLE/CONSTANT Example

Directives highlighted in this example are:

  • variable
  • constant
  • Program Functional Description

    This example shows the the usage of the variable directive, used for creating symbols which may be used in MPASM assembler expressions only. The symbols created with this directive do not occupy any physical memory location of microcontroller.

    Commented Code Listing

    list p=16f877 ;Select the device.

    #include <p16f877.inc> ;Include standard header file

    ;for the selected device.

    variable perimeter=0 ;The symbol 'perimeter' is

    ;initialized to 0

    variable area ;If a symbol is declared as

    ;variable, then initialization

    ;is optional, i.e. it may or may

    ;not be initialized.

    constant lngth=50H ;The symbol 'lngth' is

    ;initialized to 50H.

    constant wdth=25H ;The symbol 'wdth' is

    ;initialized to 25H.

    ;A constant symbol always needs

    ;to be initialized.

    perimeter=2*(lngth+wdth);The value of a CONSTANT cannot

    ;be reassigned after having been

    ;initialized once. So 'lngth' and

    ;'wdth' cannot be reassigned. But

    ;'perimeter' has been declared

    ;as variable, and so can be

    ;reassigned.

    area=lngth*wdth

    end


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