MACRO/ENDM Example
Directives highlighted in this example are:
endm
Program Functional Description
This code demonstrates the utility of
macro
directive, which is used to define a macro.Commented Code Listing
list p=16f877 ;Select the device.
#include <p16f877.inc> ;Include standard header file
;for the selected device.
result equ 20 ;Assign value 20H to label
;result.
ORG 0000 ;The following code will be placed
;in reset address 0.
goto start ;Jump to an address whose label is
;'start'.
add MACRO num1,num2 ;'add' is a macro. The values of
;'num1' and 'num2' must be passed
;to this macro.
movlw num1 ;Load W register with a literal
;value assigned to the label
;'num1'.
movwf result ;Load W register to an address
;location assigned to the label
;'result'.
movlw num2 ;Load W register with a literal
;value assigned to the label
;'num2'.
addwf result ;Add W register with the memory
;location addressed by 'result'
;and load the result back to
;'result'.
endm ;end of 'add' MACRO
org 0010 ;Main program starts at 10H.
start ;The label 'start' is assigned an
;address 10H.
add .100,.90 ;Call 'add' MACRO with decimal
;numbers 100 and 90 assigned to
;'num1' and 'num2' labels,
;respactively. 100 and 90 will be
;added and the result will be in
;'result'.
end
Microchip Technology Inc. Microchip's Web Site Voice: (480) 792-7200 Fax: (480) 899-9210 Microchip's E-mail Address |