9
\$\begingroup\$

Some background. I use MPLABx with a PicKit2 to program different types of pics. At the moment its the 16F887. I try to stick to the Hi-Tech PICC Lite tool chain but I'm growing increasingly unhappy with how some things are assembled. Operations which should be relativly fast (considering the 500ns instruction cycle at 8Mhz) are taking up to 20us to complete. So I've started inserting my own ASM code to deal with it.

However, I'm having difficulties understanding the memory map provided in the datasheet on Page 20.

Program memory starts at 0005h. However page 23 shows file addresses of special purpose registers, such as Port A for example. The address of Port A is shown as "05h".

I am confused how to differentiate between a memory location 0005h, and the special purpose register located at 05h. How do I reference the special purpose registers?

I've done pretty extensive assembler programming for older HC11 chips, but this is my first venture into PIC asm coding. Any help here would be appreciated.

\$\endgroup\$
8
\$\begingroup\$

The PIC uses what's called a "Harvard Architecture", which means that it has separate address spaces for instructions and data.

Whether an address refers to a register or an instruction depends on the context in which it is used.

The diagrams in section 2.1 "Program Memory Organization" are about program memory, or instruction address space. The diagrams in section 2.2 "Data Memory Organization" are about registers and special function registers, or data memory address space.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ So if I said "MOVWF 0x0005", the PIC would know that I am referencing address 0x0005 in the data memory, and not the program space? \$\endgroup\$ – Michael Dec 18 '12 at 22:04
  • \$\begingroup\$ @Michael: Yes. Whether the address in a instruction refers to program or data memory depends on the instruction. This is described for each opcode. Basically, if it deals with data, like MOVWF, then it will access data memory. If it deals with program addresses, like GOTO, then it will access program memory. \$\endgroup\$ – Olin Lathrop Dec 18 '12 at 22:08
  • \$\begingroup\$ Thank you. I guess the HC11 I used to do assembler in was von Neumann arch. I would often have issues of over writing my instruction code when I was just learning. Thank you again. \$\endgroup\$ – Michael Dec 18 '12 at 22:13
3
\$\begingroup\$

What Dave said, but I also want to point out that program memory starts at 0, not 5. On a reset, the processor sets the PC to 0 and starts running. On a interrupt, the processor effectively causes a call to location 4 and turns off the global interrupt enable bit. Program memory location 5 is not special, other than this will be the second instruction of the interrupt routine if you have a interrupt routine.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Yes that is understood. I meant 5 is the first generic instruction address. \$\endgroup\$ – Michael Dec 18 '12 at 22:07
  • \$\begingroup\$ @Michael: No, it's not that either. As I said, there is nothing really special about program memory location 5. The label first generic instruction address makes no sense for it. The first instruction address is 0, and 4 is a little special too due to interrupts. The rest are really not special, and "generic" makes no sense in this context. \$\endgroup\$ – Olin Lathrop Dec 18 '12 at 22:17
  • \$\begingroup\$ Ok, how about its the first non-reset, non-interrupt vector address? What I'm saying is I understand what is is your trying to say. \$\endgroup\$ – Michael Dec 18 '12 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.