
Site Search
SECTION I-3: The ADDLW instruction in the PIC micro-controller
The ADDLW instruction has the following format:
ADDLW K | ;ADD literal value |
---|
The ADD instruction tells the CPU to add the literal value K to register WREG and put the result back in the WREG register. Notice that in ADDLW, first comes the letter L (literal) and then the letter W (WREG), which means "add a literal value to WREG", the destination. To add two numbers such as 25H and 34H, one can do the following.
MOVLW 25H | ;load 25H into WREG |
---|---|
ADDLW 34H | ;add value 34 to W (W = W + 34) |
PIC WREG and ALU Using Literal Value |
---|
![]() |
Execute the above lines results in WREG = 59H (25H + 34H = 59H)
The following program will add 12H, 16H, 11H, and 43H:
MOVLW 12H | ;load value 12H into WREG (WREG = 12H) |
---|---|
ADDLW 16H | ;add 16 to WREG = 28H) |
ADDLW 11H | ;add 11 to WREG (WREG = 39H) |
ADDLW 43H | ;add 43 to WREG (WREG = 7CH) |
When programming the WREG register of the PIC micro-controller with a literal value, the following points should be noted:
- Values can be loaded directly into the WREG register. There is no need for a preceding pound sign or dollar sign to indicate that a value is an immediate value as is the case with some other micro-controllers.
- If values 0 to F are moved into an 8 bit register such as WREG, the rest of the bits are assumed to be all zeros. For example, in "MOVLW 5H" the result will be WREG = 05H; i.e. WREG = 00000101 in binary.
- Moving a value larger than 255 (FF in hex) into the WREG register will truncate the upper byte and cause a warning in the .err file.
MOVLW 7F2H | ;Illegal 7F2H > 8 bits (FFH), becomes F2H |
---|---|
MOVLW 456H | ;Illegal 456H > FFH, becomes 56H |
MOVLW 60A5H | ;Illegal but becomes A5H |