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

余生颓废 提交于 2019-12-11 02:57:19

问题


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 instruction 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)?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6984365/does-the-program-counter-always-have-to-change-upon-a-clock-tick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!