-4
\$\begingroup\$

if i want to a short jump from a memory address lets say from 0x0040 to 0x0060 the assembly code is like the below?

ORG 0x0020
GOTO 0X0060

And if i want to make a long jump from bank 1 to bank 3 for example address 0x0810 to address 0x1810 is like:

ORG 0x0810
BSF PCLATH,3
BSF PCLATH,4
GOTO 0X1810

??

\$\endgroup\$

closed as not a real question by Leon Heller, tcrosley, Brian Carlton, Dave Tweed, Olin Lathrop Mar 20 '13 at 13:26

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ which chip/family, is it for? \$\endgroup\$ – Grady Player Mar 19 '13 at 16:47
  • \$\begingroup\$ for a PIC16F877 \$\endgroup\$ – 20317 Mar 19 '13 at 16:55
  • \$\begingroup\$ How GOTO works and its relation to PCLATH is well documented in the datasheet right where you'd expect to find it. -1 for poor research and clearly not even having tried to look in the obvious place. \$\endgroup\$ – Olin Lathrop Mar 19 '13 at 17:41
3
\$\begingroup\$

It is not clear what your question actually is, but yes, you have to set PCLATH<4:3> to reliably jump to any location in program memory using a GOTO instruction on the original 14 bit PIC architecture. This is, of course, all very well described in the datasheet in several places. What exactly are you confused about?

You also have some other confusions. There is no distinction between a "long" or "short" jump. The GOTO instruction always does the same thing. The low 11 bits of the target address come from the instruction itself, and the upper 2 bits from PCLATH<4:3>. This has nothing to do with whether the two upper bits happen to be the same in the source and destination addresses or not.

No, you can't jump between bank 1 and bank 3. Data memory can not be executed, only program memory can. You can jump between pages of program memory, with the only distinction being that the upper 2 bits of the address change when jumping between pages.

If you use the convention that PCLATH<4:3> are always set to the page currently executing from and you know that the target is in the same page, then you don't have to explicitly set anything in PCLATH. However, this is a convention that is completely up to you. The hardware can be used various ways.

\$\endgroup\$
  • \$\begingroup\$ actually a very good point, that you cant jump from banks because in the harvard arch you can't execute anything from the data address set... and the terminology is different, page vs bank. \$\endgroup\$ – Grady Player Mar 19 '13 at 22:16
1
\$\begingroup\$

from: http://ww1.microchip.com/downloads/en/devicedoc/31006a.pdf

To jump between the program memory pages, the high bits of the Program Counter (PC) must be modified. This is done by writing the desired value into a SFR called PCLATH (Program Counter Latch High). If sequential instructions are executed, the program counter will cross the page boundaries without any user intervention. For devices that have less than 8K words, accessing a location above the physically implemented address will cause a wraparound. That is, in a 4K-word device accessing 17FFh actually addresses 7FFh. 2K-word devices (or less) do not require paging.

It sure seems like what you are doing would work, does it not?

\$\endgroup\$

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