Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to modify or access Program counter?

While reading about Program counter i came to know to that The Program Counter is special in that there is no way to directly modify its value.

Is there any indirect way to access/modify the content of Program Counter?

like image 588
Amit Singh Tomar Avatar asked Dec 26 '11 11:12

Amit Singh Tomar


2 Answers

You have to understand that if you modify the PC, the next instruction executed will be the one at the new PC address. That is simply an unconditional jump, and all processors have such an instruction.

Typically there is no LD PC,addr instruction, but that is exactly what JMP addr does, so it is not true that you cannot directly modify its value. You cannot however modify its value without modifying the execution path of the code - execution continues from the address specified.

In most cases it is possible to do it indirectly also, by for example setting the stack pointer to a location containing the new address and calling a RET return instruction.

Different processors and architectures may behave differently in a number of ways, and the instruction mnemonics I have suggested above are "generic" and not intended to refer to any specific instruction set.

like image 133
Clifford Avatar answered Sep 22 '22 20:09

Clifford


Unconditional jump instruction directly modifies the value of the PC.

like image 35
zvrba Avatar answered Sep 23 '22 20:09

zvrba