Program counter: Difference between revisions
imported>Dominic DeStefano No edit summary |
imported>Dominic DeStefano mNo edit summary |
||
Line 2: | Line 2: | ||
==How it Works== | ==How it Works== | ||
After an instruction is fetched from computer memory by the [[Central processing unit|CPU]], the program counter is incremented by the length of the instruction word in terms of memory units. Since the program counter counts ''memory addresses'' and not ''instructions,'' it is incremented by the number of memory units that the instruction word contains. In the case of simple fixed-length instruction word [[ISA]]s, this is always the same number. For example, a fixed-length 32-bit instruction word ISA that uses 8-bit memory words would always increment the program counter by 4 (except in the case of jumps). | After an instruction is fetched from computer memory by the [[Central processing unit|CPU]], the program counter is incremented by the length of the instruction word in terms of memory units. Since the program counter counts ''memory addresses'' and not ''instructions,'' it is incremented by the number of memory units that the instruction word contains. In the case of simple fixed-length instruction word [[Instruction set architecture|ISA]]s, this is always the same number. For example, a fixed-length 32-bit instruction word ISA that uses 8-bit memory words would always increment the program counter by 4 (except in the case of jumps). | ||
ISAs that use variable length instruction words, such as [[x86]], increment the program counter by the number of memory words corresponding to the last instruction's length. Also, note that in more complex CPUs, incrementing the program does not necessarily occur at the end of instruction execution. This is especially the case in heavily pipelined and superscalar architectures. | ISAs that use variable length instruction words, such as [[x86]], increment the program counter by the number of memory words corresponding to the last instruction's length. Also, note that in more complex CPUs, incrementing the program does not necessarily occur at the end of instruction execution. This is especially the case in heavily pipelined and superscalar architectures. |
Revision as of 14:33, 30 March 2007
A program counter is a computer register that first determines the sequence of instructions to be executed, then stores those instructions by that sequence in memory. In other words, the program counter keeps track of the CPU's place in the current program.
How it Works
After an instruction is fetched from computer memory by the CPU, the program counter is incremented by the length of the instruction word in terms of memory units. Since the program counter counts memory addresses and not instructions, it is incremented by the number of memory units that the instruction word contains. In the case of simple fixed-length instruction word ISAs, this is always the same number. For example, a fixed-length 32-bit instruction word ISA that uses 8-bit memory words would always increment the program counter by 4 (except in the case of jumps).
ISAs that use variable length instruction words, such as x86, increment the program counter by the number of memory words corresponding to the last instruction's length. Also, note that in more complex CPUs, incrementing the program does not necessarily occur at the end of instruction execution. This is especially the case in heavily pipelined and superscalar architectures.