Van: Andreas Magnusson Aan: PICLIST@MITVMA.MIT.EDU Onderwerp: Subroutines placement Datum: maandag 3 mei 1999 22:22 > Hi! Hello Andreas, > I have never really understud how to use the subroutines and the memory in a PIC16F84 > correct. > I knew I have to put subroutines in the lower area of each memoryblock. How shall I do > exactly. This is only true for Scenix controllers. It does not apply to MicroChip controllers. > Can I put a subroutine in the "lower area" and with a goto instruction go to another place > in the memory and continu the routine there....?... :-? Yes. you can. But remember that the sub-routine _has_ to end _somewhere_ with a Return. You could call a Subroutine, jump a number of different ways according to the contents of the W-register ( Case X - select) and end every "branch" with a Return. > And the memory I have read about«"long calls" and stuff like that where you have to > change the RP0, RP1 status bits. Can't really say I understund anything... If you look at the Call-instruction you can see that the instruction itself provides the 11 lower-bits of the Target-address. The PCLATH provides the 2 upper-bits. But with an address of 11 bits you have an Address-space of 2048 words of code. That's twice as much reach than the `84 has ! So, you can Call (and Goto) anywhere in the Code-memory of the `84 without changing anything in the PCLATH register. > When do I have to think about the "memory placement" when I am writing assambles? That pop's up it's ugly head when using the PCL register for indirect jumps (mostly into a Table). The PCL-register can hold only 8 bits of an address, so the rest of the address will have to come from elsewhere. So, if you add a value to the PCL register it will "wrap-around" within a page of 256 code-words. But there is something more you will have to take heed to. I said that "the rest of the address will have to come from elsewhere". Where does it come from ? Well, it comes from the PCLATH register. This means that if you want to reach a target-address in some "page" of 256 code-words by way of changing PCL, you will have to load PCLATH with that "page" -number. > If anyone want's to explaine this for me I would be very happy! > >/Andreas Magnusson Greetz, Rudy Wieser