LOCAL Example

MPASM Assembler

LOCAL Example

Directives highlighted in this example are:

  • local

Program Functional Description

This code demonstrates the utility of local directive, which declares that the specified data elements are to be considered in local context to the macro.

Commented Code Listing

list p=16f877 ;Select the device.

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

;for the selected device.

incr equ 2 ;Assembler variable incr is set

;equal to 2.

add_incr macro ;Declaration of macro 'add_incr'.

local incr ;Local assembler variable 'incr'.

incr set 3 ;Local 'incr' is set to 3, in

;contrast to 'incr' value

;of 2 in main code.

clrw ;w register is set to zero

addlw incr ;w register is added to incr and

;result placed back

endm ;in w register.

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

clrw ;W register set to zero.

addlw incr ;W register is added with the

;value of incr which is now equal

;to 2.

add_incr ;W register is added with the

;value of incr which is now equal

;to 3 (value set locally in the

;macro add_incr).

clrw ;W register is set to zero again.

addlw incr ;incr is added to W register and

;result placed in W register.

;incr value is again 2, not

;affected by the value set in the

;macro.

goto $

service_int

retfie

end


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