Jinx, Soon after sending my question I've realized I have to play with MPLAB and its memory map view. Anyway, your detailed explanation is revealing:o) Thank you very much. On 8/31/07, Jinx wrote: > > Hi Carol, > > > I think this has to do with the fact I'm still not so sure about PIC > > memory > > Each datasheet has a memory map. In your editor (MPLAB ?) you > can see where instructions are put after compilation. Select View / > Program Memory > > > and where or in which order set the ISR, inicialisation part, > > main program and then the subrrutines. > > At the bottom of memory are the jump vectors. For the F87x there > are just two ; Reset, at location 00 and Interrupt, at location 04. > Memory for the user's program starts at 05 > > Say you have this (it's not how you might normally do it but just > as an example) > > org 0x000 > goto main > > og 0x004 > goto isr > > org 0x080 ; interrupt service routine starts at location 0x080 > isr code > > org 0x100 ; main body starts at location 0x100 > main code > > After compilation of the above you'll see in memory > > 000 2900 GOTO MAIN ; jump to MAIN after a reset > (blank, 3FFFs) > 004 2880 GOTO ISR ; jump to ISR on an interupt > (blank, 3FFFs) > 080 ISR code > > 100 MAIN code > > Say you didn't include orgs, and had just a Reset jump and some ISR > code before MAIN > > GOTO MAIN > irq movwf w_temp > swapf STATUS,W > clrf STATUS > movwf status_temp > retfie > main GOTO INIT > Loop BSF PORTA,0 > CALL delay > GOTO Loop > > Would compile as > > 000 GOTO MAIN > 001 MOVWF W_TEMP ; IRQ > 002 SWAPF STATUS,W > 003 CLRF STATUS > 004 MOVWF STATUS_TEMP > 005 RETFIE > 006 GOTO INIT ; MAIN > 007 BSF PORTA,0 > 008 CALL DELAY > 009 GOTO 007 > > Program code is in the 0x004 vector. Which will do no harm if > interrupts are not being used > > With (the recommended) orgs > > org 0x000 > goto main > org 0x004 > goto irq > > actual code would compile into memory directly after the vectors (at > 0x005) > > 000 GOTO MAIN > 001 3FFF > 002 3FFF > 003 3FFF > 004 GOTO IRQ > 005 MOVWF W_TEMP ; IRQ > 006 SWAPF STATUS,W > 007 CLRF STATUS > 008 MOVWF STATUS_TEMP > 009 RETFIE > 00A GOTO INIT ; MAIN > 00B BSF PORTA,0 > 00C CALL DELAY > 00D GOTO 00B > > As for where routines can go, that's largely a matter of personal > taste. Some people put the ISR at the bottom of memory, mine > are usually in the body of the code. 'Library' routines such as delays > or display drivers are at the end of code, out of the (my) way. It > can sometimes be helpful to put data in the same page as the calling > routine so you don't need to worry about PCLATH. Mostly issues > like that are a minor inconvenience though > > > However, in other examples, I try to do it this way -subrrutines > > at the last part of the whole code- and compiler do not make its job > > saying I'm "Overwriting previous address contents (0000)" > > Possibly you're putting an org too high in memory for the size of the > routines and the code is wrapping around to the start address > > > May be you know some tutorial I can read about this issue. > > You could try MPLAB's Help / Topics / MPASM Assembler. For > example the differences between absolute and relocatable code, org, > memory useage, RAM bank access, interrupt handling etc > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist