J
John
I want to understand the usage of _SP in turbo C. Is _SP the stack
pointer register of the CPU? That means _SP should point to the
top of the procedure call stack when we make function calls? I assume
_SP is only useful when making function calls here.
Here's the program I wrote to test out how _SP behaves, but the result
is
main sp=-10
func1 sp=-14
func2 sp=-18
Why the result has negative values?
But if I put _SP = 10; in the program, then I got the following result,
the interesting part is main sp is still -10. And I got illegal
instruction pop up error message.
main sp=-10
func1 sp=6
func2 sp=2
So does it mean _SP allows us to manipulate where is the top of the
call stack manually?? Please advice for the practical usage??
thanks...
-------------------------------------------------
#include <stdio.h>
#include <conio.h>
void func1(void);
void func2(void);
void main(void)
{ //_SP = 10;
printf("main sp=%d\n",_SP);
func1();
}
void func1(void)
{ printf("func1 sp=%d\n",_SP);
func2();
}
void func2(void)
{ printf("func2 sp=%d\n",_SP);
}
pointer register of the CPU? That means _SP should point to the
top of the procedure call stack when we make function calls? I assume
_SP is only useful when making function calls here.
Here's the program I wrote to test out how _SP behaves, but the result
is
main sp=-10
func1 sp=-14
func2 sp=-18
Why the result has negative values?
But if I put _SP = 10; in the program, then I got the following result,
the interesting part is main sp is still -10. And I got illegal
instruction pop up error message.
main sp=-10
func1 sp=6
func2 sp=2
So does it mean _SP allows us to manipulate where is the top of the
call stack manually?? Please advice for the practical usage??
thanks...
-------------------------------------------------
#include <stdio.h>
#include <conio.h>
void func1(void);
void func2(void);
void main(void)
{ //_SP = 10;
printf("main sp=%d\n",_SP);
func1();
}
void func1(void)
{ printf("func1 sp=%d\n",_SP);
func2();
}
void func2(void)
{ printf("func2 sp=%d\n",_SP);
}