SECTION V-8: Using EQU for RAM Address Assignment

The common usage of EQU is for the address assignment of the general purpose region of the file register. Examine the following rewrite of an earlier example using EQU:

MYREG EQU 0x12 ;assign RAM location to MYREG
MOVLW 0 ;clear WREG, WREG = 0
MOVWF MYREG ;clear MYREG, location 12H has 0
MOVLW 22H ;WREG = 22H
ADDWF MYREG, F ;MYREG = WREG + MYREG
ADDWF MYREG, F ;MYREG = WREG + MYREG
ADDWF MYREG, F ;MYREG = WREG + MYREG
ADDWF MYREG, F ;MYREG = WREG + MYREG

 

 

 

 

 

 

 

This is specially helpful when the address needs to be changed in order to use a different PIC chip for a given project. It is much easier to refer to a name than a number accessing RAM address locations.

The following program will move value 9 into RAM locations 0 - 4, then add them together and place the sum in location 10H

 

MYVAL EQU 9 ;MYVAL = 9
R0 EQU 0 ;assign RAM addresses to R0
R1 EQU 1 ;assign RAM addresses to R1
R2 EQU 2 ;assign RAM addresses to R2
R3 EQU 3 ;assign RAM addresses to R3
R4 EQU 4 ;assign RAM addresses to R4
SUM EQU 10H  
MOVLW MYVAL ;WREG = 9
MOVWF R0 ;RAM location 0 has 9
MOVWF R1 ;RAM location 1 has 9
MOVWF R2 ;RAM location 2 has 9
MOVWF R3 ;RAM location 3 has 9
MOVWF R4 ;RAM location 4 has 9
MOVLW 0 ;WREG = 0
ADDWF R0, W ;WREG = R0 + WREG
ADDWF R1, W ;WREG = R1 + WREG
ADDWF R2, W ;WREG = R2 + WREG
ADDWF R3, W ;WREG = R3 + WREG
ADDWF R4, W ;WREG = R4 + WREG
MOVWF SUM  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

More From Iamtechnical.com

Advertisement:

SiteLock