ARM is unusual among the processors by having the program counter available as a “general purpose” register. Most other processors have the program counter hidden, and its value will only be disclosed as the return address when calling a function. If you want to modify it, a jumping instruction is used.
For example, on the x86, the program counter is called the instruction pointer, and is stored in
eip, which is not an accessible register. After a function call,
eip is pushed onto the stack, at which point it could be examined. Return is done through the
ret instruction which pops the return address off the stack, and jumps there.
Another example: on the MIPS, the program counter is stored into register
31 after executing a
JALR instruction, which is used for function calling. The value in there can be examined, and a return is a register jump
JR to that register.
ARM’s unusual design allows many, many ways of returning from functions. But first, we must understand how function calls work on the ARM.(more…)