SECTION VI-10: Executing a Program Byte by Byte

The list file program in previous section when burned into the ROM of a PIC18 chip, the following step by step description of the action of the PIC upon applying power to it:

 

  • When the PIC is powered up, the program counter PC has 00000 and starts to fetch the first opcode from location 00000 of the program ROM. In this program the first opcode is 0E, which is the code for moving an operand to WREG. When the opcode is executed, the CPU places the value of 25 in WREG. When one instruction is finished, the program counter is incremented to point to 00002, PC = 00002, which contains opcode 0F, the opcode for the instruction "ADDLW 34H".
  • When opcode 0F is executed, the value 34H is added to WREG. Then the program counter is incremented to 0004.
  • ROM location 0004 has the opcode for instruction "ADDLW 11H". This instruction is executed and now PC = 00006.
  • This process goes on until all the instructions up to "MOVWF SUM" are fetched and executed. All the above instructions are 2-byte instructions. Each one takes 2 memory locations.
  • The program counter PC = 000E points to the next instruction, which is "GOTO HERE". This is a 4 byte instruction. It takes ROM addresses of 0E, 0F, 10, and 11. After the execution of this instruction, PC = 0000E. This keeps the program in an infinite loop. If there is a monitor program in PIC trainer, then the program will go back to the monitor program  and we do not have to use the GOTO instruction. The fact that the program counter points at the next instruction to be executed explains why some microprocessors notably the x86, call the program counter the instruction pointer.

 

Program ROM Contents 
ADDRESS CODE
000000 0E
000001 25
000002 0F
000003 34
000004 0F
000005 11
000006 0F
000007 12
000008 0F
000009 1C
00000A 0F
00000B 06
00000C 6E
00000D 10
00000E 07
00000F EF
000010 00
000011 F0
000012  

 

More From Iamtechnical.com

Advertisement:

SiteLock