| Home | Price List | Order Info | Microcontrollers | Assembler | C and C++ |
| ORG 0005h Directive |
|
Recently I received a letter from a very satisfied customer asking me why my programmes always have an ORG 0005h directive even when this follows directly from the interrupt vector which is at 0004h. The answer is of course that the ORG 0005h directive is not necessary in virtually all of my programmes. I put it there purely to emphasise the important of starting the programme text at the memory location number five. It also helps to introduce newcomers to the idea of hexadecimal numbers. This raises an interesting question - Why do we always need to start PIC programmes at 0005h? When a PIC is switched or reset the programme counter is set to zero. This means that the very first instruction that the PIC actions is taken from memory location 0000h. We must ensure that memory location zero always contains a suitable start instruction for our programme. Usually we put a GOTO instruction at this point to skip over the next four memories but if we are writing a programme which does not use interrupts we can start our programme at memory location zero. The only reason we need to start our programmes at memory location 0005h is because the interrupt vector is located at 0004h. In simple terms what this means is that if our programme uses interrupts the programme will restart at 0004h every time an interrupt occurs. All my programmes, even the very simplest, start at 0005h and by doing so they start the process of understanding the more complex concepts of hexadecimal numbers and interrupts. This is the natural way of learning. |