What value does the Program Counter have at the end of a program?

549 Views Asked by At

I know that the program counter will always point to the memory location of the next instruction, however at the end of the program, what would be the value of the program counter?

Would the value be the same as the last instruction that was run in the program?

1

There are 1 best solutions below

7
Hack Saw On

It depends on what you mean by "end". In a multitasking system the program, as far as the CPU is concerned, is probably still going, having moved on to whatever the next task is. In this particular case, the PC will contain the address which the routines have loaded into it to move onto the next task.

If you are talking about the giant program which is the OS, or whatever single program you might be running on a small chip like an ATMEL, it will likely contain an address somewhere in memory which happened to be one containing a HALT instruction. Depending on the chip, it might then power off, or just hang, doing nothing until an external signal resets the chip, whereupon it'll contain whatever value the chip defaults to on startup.