开发者

Does the program counter always have to change (upon a clock tick)?

I'm not so familiar with computing (software) theory, and I thought about this question - does the PC (program counter) always have to change (I guess, upon each new clock tick)?

I searched a bit online, and found Commodore 64 Programmers Reference Manual (heh :)) that confirms it: "...Commodore 64 (or, for that matter, any computer), the program counter is always changing" (as well as Chapter 6: Hard, soft or firm?); but I just wanted to have it commented here.

I was thinking, if an i开发者_如何学编程nstruction set the PC (or rather next PC), so the next execution address is same as its current one, there would be no way to exit that loop (unless there is some extern interrupt, of course)?


The program counter changes when it needs to change. If your current instruction takes a while, or your program isn't the current one being executed (remember, most computers are running more than one thread of execution) then it is not necessary that it change on every clock tick.

Yes, changing the PC so that it changes itself to the beginning of a set of instructions that sets itself to the beginning of a set of instructions that sets itself... as you can see, yes, this would cause an infinite loop. This is pretty much what the old '20 GOTO 10' situation was about.


Generally speaking, the program counter doesn't have to change on every clock tick. An instruction could take a number of clock ticks to execute, and then when it finished, the program counter would change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜