In compilation courses I see: ARP (active recording pointer?? or Activation Record Pointer??) and: OLD ARP. I understand that it is used to get the parameters in the stack, or to get the local variables. But I don't understand more about it (is it like the EBP register ?). And I don't understand the utility of the OLD ARP too.
Below an example :
void main(void){
f(0);
}
void f(int n){
int m;
int [2] tab;
m=n;
}
and the stack of the f function :
|///////////|
|-----------|
| n:0 |
|-----------|
| @retour |
|-----------|
| OLD ARP | // <---- ARP
|-----------|
| m |
|-----------|
| tab | // pointing on the case : "tab[0]"
|-----------|
| tab[0] |
|-----------|
| tab[1] |
|-----------|
|///////////|
And the pseudo-code generate from the C :
main:
PUSH 0
CALL f
RET
f:
PUSH ARP //--------------------------|
ARP=SP |
SP = SP - nb_temp*w // with w = word | PRELUDE
//ALLOC array //---------------------|
[ARP-w]=[ARP+2w]
SP=ARP //----------------------------|
POP ARP | POSTLUDE
RET 1*w //---------------------------|
ARP stands for Activation Record Pointer. In x86 it is the EBP register.
The ARP is used to keep track of where the most recent function activation record is. Whenever a new function call is made, the old value of the ARP is added to the new activation record and then the ARP is updated to point at it. Whenever a function returns, the ARP's old value is restored from the activation record it is currently pointing to, so that it now points to the parent function.
In the example, OLD ARP in f's activation record points to the activation record of main. This lets the ARP be restored to point to main after f finishes.