Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MPLAB SIM Not Giving Expected Results

Status
Not open for further replies.

Inquisitive

Super Moderator
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
 
hi Inq,
Check the PIC's memory map for location 0x12.?
Eric
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    9.5 KB · Views: 208
Do I specify 12H as a viewable location or have to set it up somehow. It is not an option in "Watch" window
 
Notice how the address for W shows as 000 and WREG as FE8.

ck3qfgt356y6qltny.png
 
Like Eric said, you still have to consider where program memory starts. What harm is there is doing what he suggested?

What version of MPLab are you using?

JOhn
 
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.
 
Since you clear f, adding w to it repeatedly and keeping your destination as w will not change w.

John
 
So there is no way to see this process in action?
 
hi Inq,
If you post your full code, I will try to see if I get the same result.
Eric
 
You should be able to see the result of every transaction in between registers.

In my office now (yes, Sunday). I will simulate and tell the outcome this afternoon.
 
The complete code is in post #1
 
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
E
 
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

Eric
 
Thanks Eric. That works.

From what is seen here the file register F is viewable but W is not.

Thanks to all who helped. Much appreciated.
 
That is correct, w itself is not viewable. But all of the chips I have seen had an SFR called WREG or something similar, which mirrors w.

John
 
At least all the 18Fs do.
 
Status
Not open for further replies.

Latest threads

Back
Top