TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vikrampschauhan
NA
4
0
Variables on the stack and their mapping???
Dec 13 2004 7:18 PM
In the function - void main() { int i=10; int j=20; int sum=i+j; return; } Following happens - 1. push(int); - the sp is incremented by int bytes. This space(bytes){b/w sp's previous value and incremented value} is marked as i. 10 is put in this space. 2. push(int); - the sp is incremented by int bytes again. This space(bytes) is marked as j. 20 is put in this space. 3. push(int); - the sp is incremented by int bytes again. This space(bytes) is marked as sum. 30 is put in this space. When the function returns, everything is popped from the stack in the reverse sequence: 1. pop(int) ; - sp is decremented by int bytes. Now sp points to the begining of sum(30) and sum can be overwritten. 1. pop(int) ; - sp is decremented by int bytes again. Now sp points to the begining of j(20) and j can be overwritten. 1. pop(int) ; - sp is decremented by int bytes again. Now sp points to the begining of i(10) and i can be overwritten. Now, there must also be a table that maps the variables to their corresponding address: For eg a table containing the following entry: i - 0xAAAA (ie starting address of i) j - 0xBBBB (ie starting address of j) sum - 0xCCCC (ie starting address of sum) so that when we refer i, we know what address are we talking about(eg when we say i=10;) What is this table and at what point is it destroyed? Thanks Vikram
Reply
Answers (
2
)
put application on web
Indexer:Why to use it if Public array can solve the purpose