SECTION V-5: Assembler Directives EQU - Equate

Instructions tell the CPU what to do. Directives, also called pseudo-instructions give directions to the assembler. The MOVLW and ADDLW instructions are commands to the CPU, but EQU, ORG and END are directives to the assembler. The widely used directives of the PIC are EQU and SET.

EQU (equate) :-

This is used to define a constant value or a fixed address. The EQU directive does not set aside storage for a data item, but associates a constant number with a data or an address label so that when the label appears in the program, its constant will be substituted for the label. The following uses EQU for the counter constant, and then the constant is used to load the WREG register:

COUNT EQU 0x25 ;total count as counter number
................. ............              ..........
MOVLW COUNT ;WREG = 25H

 

When executing the above instruction "MOVLW COUNT", the register WREG will be loaded with the value 25H. 

What is the advantage of using EQU?

Assume that a constant, a fixed value, is used through out the program, and the programmer wants to change its value everywhere. By the use of EQU, the programmer can change it once and the assembler will change all of its occurrences throughout the program, rather than search the entire program trying to find every occurrence.

SET:-

This directive is used to define a constant value or a fixed address. In this regard, the SET and EQU directives are identical. The only difference is the value assigned by the SET directive may be reassigned later.

 

More From Iamtechnical.com

Advertisement:

SiteLock