Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify "top of the stack" #36

Open
vedantroy opened this issue Jul 19, 2020 · 0 comments
Open

Clarify "top of the stack" #36

vedantroy opened this issue Jul 19, 2020 · 0 comments

Comments

@vedantroy
Copy link

vedantroy commented Jul 19, 2020

It would be helpful to use different term than "top" to refer to the first "element" in the stack that would be popped off. Maybe, tip or head?

Here's a sentence that felt confusing:

"".b+12(SP) and "".a+8(SP) respectively refer to the addresses 12 bytes and 8 bytes below the top of the stack (remember: it grows downwards!).

From this sentence, I thought the stack looked like as follows (here the stack is growing downwards):

RETURN ADDRESS 0(SP)
Argument A 8(SP)
Argument B 12(SP)

However, the diagram in the book is as follows:

   |    +-------------------------+ <-- 32(SP)              
   |    |                         |                         
 G |    |                         |                         
 R |    |                         |                         
 O |    | main.main's saved       |                         
 W |    |     frame-pointer (BP)  |                         
 S |    |-------------------------| <-- 24(SP)              
   |    |      [alignment]        |                         
 D |    | "".~r3 (bool) = 1/true  | <-- 21(SP)              
 O |    |-------------------------| <-- 20(SP)              
 W |    |                         |                         
 N |    | "".~r2 (int32) = 42     |                         
 W |    |-------------------------| <-- 16(SP)              
 A |    |                         |                         
 R |    | "".b (int32) = 32       |                         
 D |    |-------------------------| <-- 12(SP)              
 S |    |                         |                         
   |    | "".a (int32) = 10       |                         
   |    |-------------------------| <-- 8(SP)               
   |    |                         |                         
   |    |                         |                         
   |    |                         |                         
 \ | /  | return address to       |                         
  \|/   |     main.main + 0x30    |                         
   -    +-------------------------+ <-- 0(SP) (TOP OF STACK)

Looking at this diagram I see that the top of the stack refers to the bottom of the stack, but it might be nice to use different terminology.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant