GLOBAL/EXTERN Example

MPASM Assembler

GLOBAL/EXTERN Example

Directives highlighted in this example are:

  • global
  • extern
  • Program Functional Description

    The program main.asm, along with sub.asm, demonstrate the utility of the GLOBAL and EXTERN directives, which make it possible to use symbols in modules other than where they are defined.

    Commented Code Listing

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

    ;main.asm

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

    list p=16f877 ;Select the device.

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

    ;for the selected device.

    UDATA

    delay_value res 1

    GLOBAL delay_value ;The variable 'delay_value',

    ;declared GLOBAL in this

    ;module, is included in an

    ;EXTERN directive in the module

    ;sub.asm.

    EXTERN delay ;The variable 'delay', declared

    ;EXTERN in this module, is

    ;declared GLOBAL in the module

    ;sub.asm.

    RST CODE H'0' ;The code section named RST

    ;is placed at H'0'. The

    ;instruction 'goto start' is

    ;placed in code section RST

    goto start ;Jumps to the location labelled

    ;'start'.

    INTRT CODE H'4' ;The code section named INTRT is

    ;placed at H'4'. The instruction

    ;'goto service_int' is placed in

    ;code section INTRT.

    goto service_int ;Jumps to the location labelled

    ;'service_int'.

    PGM CODE ;This is the begining of the

    ;code section named PGM. It is a

    ;relocatable code section since

    ;no absolute address is given

    ;along with directive 'CODE'.

    start movlw D'10'

    movwf delay_value

    xorlw H'80'

    call delay

    goto start

    service_int

    retfie

    end

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

    ;sub.asm

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

    list p=16f877 ;Select the device.

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

    ;for the selected device.

    GLOBAL delay ;The variable 'delay' declared

    ;GLOBAL in this module is

    ;included in an EXTERN directive

    ;in the module main.asm.

    EXTERN delay_value ;The variable 'delay_value'

    ;declared EXTERN in this module

    ;is declared GLOBAL in the

    ;module main.asm.

    PGM CODE

    delay

    decfsz delay_value,1

    goto delay

    return

    end


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