Using Assembly language on MPLAB IDE 8.92.
Trying to walk through a few steps of code in MPLAB SIM and see how the program functions. It is not working like expected. Could somebody shed some light as to what I'm doing wrong or is not obvious to me.
At the end of this routine 12H should have a value of 22H and WREG = 88H
But, I'm not getting that. I only get 22H in WREG and 0 (zero) in W during simulation W does not change.
Also I'm not able to view location 12H in the simulator.
Any pointers or suggestion would be appreciated.
Here is the code I'm using:
Code:
#include <p18f458.inc>
LIST P=18F458 ;directive to define processor
;
org 0x000
;
MOVLW 0 ; moves (0) zero to WREG to clear it
MOVWF 12H ; moves WREG to location 12H to clear it
MOVLW 22H ; load WREG with value 22H
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
;
end
With all due respect I did try 0x30 and it also showed zero address. I had a copy of the screen snapshot handy and it also showed zero at 0x20 so I used that screenshot as my example. It did not seem to make a difference. MPLAB version is 8.92.
Hi Inq,
Try this.
Make the Destination the Reg not the Acc
Code:
org 0x000
;
MOVLW 0 ; moves (0) zero to WREG to clear it
MOVWF 12H ; moves WREG to location 12H to clear it
MOVLW 22H ; load WREG with value 22H
ADDWF 12H,F ; add WREG and location 12H
ADDWF 12H,F ; add WREG and location 12H
ADDWF 12H,F ; add WREG and location 12H
ADDWF 12H,F ; add WREG and location 12H
;
end
MOVLW 0 ; moves (0) zero to WREG to clear it
MOVWF 12H ; moves WREG to location 12H to clear it
MOVLW 22H ; load WREG with value 22H
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
ADDWF 12H, W ; add WREG and location 12H, WREG = sum
hi Inq,
This original code does the following:
Clears location (12h)
Loads W with 22h
Adds W to contents of loc (12h) ; which is Zero and load the result into W, which is 22h
So you have still got 22h in W and 0 in (12h)
Adds W to contents of loc (12h) ; which is Zero
So you have still got 22h in W and 0 in (12h)
Adds W to contents of loc (12h) ; which is Zero
So you have still got 22h in W and 0 in (12h)
Adds W to contents of loc (12h) ; which is Zero
So you have still got 22h in W and 0 in (12h)
At the end you have still got 22h in W and loc(12)=0