How to see the value of W register and other general purpose registers in MPLAB ide

Thread Starter


Joined Jul 2, 2018
I wanted to know the content of W register and content of the adress location 12H in pic 16f84 micrcontroller.
I have write this simple code

RES_VECT  CODE    0x0000         
GOTO    START                  
MAIN_PROG CODE                     
MOVLW b'11';// w contains 3
MOVWF 12H ; // 12H contains 3
MOVLW b'100'; // w contains 4
ADDWF 12H, W ; // w contains 7
ADDWF 12H, W ; // w contains 10
ADDWF 12H, W;  // w contains 13
ADDWF 12H, W; // w contains 16
The code was compiled successfully. Here is a picture of it

But the problem is when I open the SFR View window (Window>PIC memory views>SFRs) to see the content of the w register of the target device for the current project.

It shows WREG content is 19. Even if I do not write the code it shows WREG content is 19. That means The code I wrote is not affecting the ‘w’ registers at all.
since the result will be 16 . My question is how I can view my correct answer in MPLAB ide?



Joined Mar 10, 2019
I coded your ASM code into Oshonsoft IDE and get what you are seeing. Using the "W" as a "flag" in the ADDWF is causing your result. Because the low bit of "W" is zero, the ADDWF (add with W using "FLAG"), the value in location 12H is added to W and stored in W.
Try code like ADDWF, 12H,1 and you will see different result. See last screen picture for result!
Note that the highlighted code on the right is what will be executed NEXT. Register display is for code executed in line above (or none at start)

Last capture is using ADDWF 12H,1 This directs the addition to be sent back to location 12H:



Joined Mar 10, 2019
Remember that ADDWF f,d uses "d" as a flag, it is not a register! W and location f are added and the flag "d" determines where the result is to be stored. Flag of "0" means store result in W. Flag of "1" means store result in location "f".
"d" is never intended to be a register, it is a bit flag only. Using a register instead (incorrect use of variable for flag) means it will only look at the low bit to determine the flag value.