MPLAB Machine code and symbolic codes

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
Dear All

Picture 1 for my program sample code

Image 1


Image 2 Machine code view



Image 3 Symbolic codes view


All together


My doutes is in sys_init subroutine, it shows TRISC SFR as PORTC and both TRISC and PORTC machine codes are same

Please advice
Thanks in advance
 

Attachments

  • Pro.JPG
    37.9 KB · Views: 130
  • sym.JPG
    38.5 KB · Views: 137
Last edited:

Hi,
Have you looked at PIC16F877/876 REGISTER FILE MAP? Did you read the paged memory architecture of PIC16F devices?
Please noticed that PORTC and TRISC are located in register Banks? So when ever you select either of these registers (port or trisc) the compiler is intelligent to handle this situation and switches bank accordingly. Enjoy!
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear babar thanks for the reply

I did bank selection correctly
Please see attached image which same my first post


Please advice more
Thanks in advance
 

Hi,

Also suggest you use the banksel directive instead of the BSF STATUS ,5 /RP0-1 etc which makes is so hard to see what bank you are in and so easy to get mixed up.

banksel PORTC
etc
banksel TRISC
etc
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Hi Dear wp100

Thanks for advice

But my program is working well in real hardware

Please advice
What should be the reason MPLAB display such wrong data?

Thanks in advance

Dear wp100 I change banksel instead of BSF STATUS,5. so still MPLAB display same

Please advice

- - - Updated - - -

Hi, Switch to the required bank first and then write the instruction.

Yes I did it correctl

Code:
sys_init	clrf	PORTC
			banksel	TRISC
			clrf	TRISC
			banksel	PORTC
			return

hopefully my question is understood correctly, this is not banks election problem and problem is the way MPLAB display in program memory view as I pointed out using pictures in my first post

Please advice
 
Last edited:

Hi,
Seems that you are initializing the micro. Please see the start up value of the status register when microcontroller boots up. If i not forgetting the default bank select is bank zero. When you clear the port and then select the tris register the bank switches and then after it switches back to bank 0. In short MPLAB is not showing wrong data. Assembler translates from this file to hex file. How could it be wrong? Hope you understood that! Enjoy
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating

ok Thanks for reply

This is my program

Code:
#include <p16f877a.inc>
LIST p=16f877a
__config 3f39
			org		0x00
Start		goto	main
main		call	sys_init
sys_init	clrf	PORTC
			banksel	TRISC
			clrf	TRISC
			banksel	PORTC
			return
end

After successfully bulled

Please click view in MPLAB IDE then program memory
view > program memory
then you can see in the program memory menu opcode HEX / Machine / Symbolic sub menus

in the Symbolic menu you can see like attached picture
I am showing it in red color
It should be clrf TRISC, but it shows clrf PORTC



Hopefully you understand my explain

Please advice
 

Hi,

Think it must be a problem with version 8.53 as your code shows correctly in v8.90 ( though beware there is mention on Microchips Programmer forum about a bug that affects some 16F chips and suggests you reload v8.8)

Edit
Opps - was looking at the Disassembly listing, not the Program Memory listing, it does still show the PORTC when its actually TRISC - clearly it must be a short coming of that listing in that it does not interpret the register with the bank selected when you View it, though clearly it does correctly run the code.


Have just added ARESL in bank 1 but again the program listing shows ADRESH .
 

Attachments

  • 2013-04-16 12_36_01-billyboy - MPLAB IDE v8.90 - Disassembly Listing.jpg
    92.3 KB · Views: 100
Last edited:
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Hi, I clearly understood your question in first few posts. You can understand it like this. Say you have two memories of some 'X' bytes. You want to write data to Memory 1, You select its CS pin and write data to lets say 0x20 location. Now if you want to write data to memory 2 you deselect memory 1 (switches bank) and write to 0x20 location again of memory 2. Now say that 0x20 location name is portc in memory 1, what should be the name of memory 2 of same location? it shold be portc there rather than trisc. Means to say that MPLAB assembler selects memory/bank correctly and write data accordingly. The names do not matter here only the address location and bank matters. Hope it is clear now. Chill
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating


Thanks for reply

But if you can please see list file it shows correct manner
You may correct but should fight with you until i understand the realistic

As per register definition file <p16f877a.inc>

PortC and trisC are in defefent address portC in 0x07 and TRISC in 0x87



Code:
MPASM  5.36                    ROTATE_OFF.ASM   4-16-2013  16:13:08         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 
                      00002 #include <p16f877a.inc>
                      00001         LIST
                      00002 ; P16F877A.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00400         LIST
Warning[205]: Found directive in column 1. (LIST)
                      00003 LIST p=16f877a
Warning[205]: Found directive in column 1. (__config)
2007   3F39           00004 __config 3f39
0000                  00005                         org             0x00
0000   2801           00006 Start           goto    main
0001   2002           00007 main            call    sys_init
                      00008                 
                      00009                         
                      00010 
                      00011 
0002   0187           00012 sys_init        clrf     [COLOR="#FF0000"]PORTC[/COLOR]
0003   1683 1303      00013                         banksel TRISC
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0005   0187           00014                         clrf    [COLOR="#FF0000"]TRISC[/COLOR]
0006   1283 1303      00015                         banksel PORTC
0008   0008           00016                         return
Warning[205]: Found directive in column 1. (end)
                      00017 end
MPASM  5.36                    ROTATE_OFF.ASM   4-16-2013  16:13:08         PAGE  2






- - - Updated - - -



Dear Wp100 Really thanks for the good news

Please confirm in your attachment file got from v8.90?

Problem remaining it too

As you pint out list file is correct

Can you please see the babar_ali pointed out in his post #10. it is very interesting to me and I tried it practically with my real hardware so it is working


Thanks in advance
 
Last edited:

Dear wp100
I installed MPLAB v8.90, still problem is remaining unchanged

please advice more
Thanks in advance
 
Last edited:

Try to understand a simple fact. The program memory and disassembly listing is decoding a single instruction.

If you have hex code 0187, it can have four differen meanings, depending on the bank select register content
CLRF PORTC
CLRF TRISC
CLRF PORTF
CLRF TRISF

The disassembler doesn't analyze register contents, it always assumes CLRF PORTC, as seen in your listing.

You may wan't to review the description of CLRF instruction in the MID-RANGE MCU FAMILY manual to understand why. As all direct addressing instructions, CLRF has only seven bits in the address field.

Your code seems to be cut in the middle, missing continuation after return from sys_init.
 
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear FvM I am glad to hear from you

This is good point 0187
01 = 0000001 seven bit instructions....... Yes Understood

But

87 should be TRISC or memory shell address of bank1

If we look at following Instractions

clrf PORTC = Hex code = 0187
clrf TRISC = hex code = 0187

let's we assume 87h = 135 but no location in bank 0, it end of 127
as per above 87 in bank 0, 8 should be removed, when decoding??????????


I know that if we selected bank correctly it doesn't matter, fortunately PORTC and TRISC in same location in different bank

Please advice
More
 
Last edited:

Dear All
Let's assume like this

Code:
Banksel PORTC
clrf       TRISC


When above code is executing the 0x07 location which PORTC is cleared but it is bank0

Let's we look at Hex code for above instruction ( clrf TRISC )

0187

PIC it decodes as 01 = clrf

87 = address of TRISC bank1

How PIC identify the address 0x07 from 87


Please advice
Thanks in advice
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…