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

Thread Starter

khatus

Joined Jul 2, 2018
95
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

Code:
RES_VECT  CODE    0x0000         
GOTO    START                  
MAIN_PROG CODE                     
START
MAIN
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
END
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?

 

sagor

Joined Mar 10, 2019
908
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)
Capture0.JPG
Capture1.JPG
Capture2.JPG
Capture3.JPG
Capture4.JPG
Capture5.JPGCapture6.JPG
Capture7.JPG

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

capture_no_W.JPG
 

sagor

Joined Mar 10, 2019
908
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.
 
Top